• usaco-palsquare-pass


    这个居然还一下就通过了,呵呵:

    /*
    ID: qq104801
    LANG: C++
    TASK: palsquare
    */
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <assert.h>
    
    /* for debug only:counter
    */
    void debug_dummy(void)
    {
        return;
    }
    
    int base;
    char x[64],y[64];
    char num[]={'0','1','2','3','4','5','6','7','8','9',
                'A','B','C','D','E','F','G','H','I','J'};
    
    void xnum(int a,int b,char* xx)
    {
        int i=0;
        int c=a;
        int l;
        char y[64];
        while(c!=0)
        {
            y[i]=num[c%b];
            c=c/b;
            i++;
        }
        y[i]='';
        l=strlen(y);
        for(i=0;i<l;i++)
        {
            xx[i]=y[l-i-1];
        }
        xx[++i]='';
        //printf("%s  len:%d
    ",x,strlen(x));    
    }
    
    int ispalindromes(char* s)
    {
        int l=strlen(s);
        int f=1;
        for(int i=0;i<(l/2);i++)
        {
            if(s[i]!=s[l-i-1])
            {
                f=0;
                break;
            }
        }
        return f;
    }
    
    void test(FILE* f)
    {
        int bb;
        for(int i=1;i<301;i++)
        {
            bb=i*i;
            xnum(bb,base,x);
            if (ispalindromes(x))
            {
                xnum(i,base,y);
                fprintf(f,"%s %s
    ",y,x);
                //printf("%d %d
    ",i,bb);
            }
        }
    }
    
    main () {    
        FILE *fin = fopen ("palsquare.in", "r");
        FILE *fout = fopen ("palsquare.out", "w"); 
        fscanf(fin,"%d",&base);
        //printf("%d
    ",base);
        test(fout);    
        
        fclose(fin);
        fclose(fout);
        exit (0);
    }

    测试用例:

    USER: ll tom [qq104801]
    TASK: palsquare
    LANG: C++
    
    Compiling...
    Compile: OK
    
    Executing...
       Test 1: TEST OK [0.011 secs, 3496 KB]
       Test 2: TEST OK [0.014 secs, 3496 KB]
       Test 3: TEST OK [0.008 secs, 3496 KB]
       Test 4: TEST OK [0.003 secs, 3496 KB]
       Test 5: TEST OK [0.003 secs, 3496 KB]
       Test 6: TEST OK [0.003 secs, 3496 KB]
       Test 7: TEST OK [0.003 secs, 3496 KB]
       Test 8: TEST OK [0.003 secs, 3496 KB]
    
    All tests OK.
    
    Your program ('palsquare') produced all correct answers! This is your submission #2 for this problem. Congratulations!
    
    Here are the test data inputs:
    
    ------- test 1 ----
    10
    ------- test 2 ----
    2
    ------- test 3 ----
    5
    ------- test 4 ----
    11
    ------- test 5 ----
    15
    ------- test 6 ----
    18
    ------- test 7 ----
    20
    ------- test 8 ----
    3
    
    Keep up the good work!
    Thanks for your submission!

    说明理解了题意。

    /***********************************************

    看书看原版,原汁原味。

    不会英文?没关系,硬着头皮看下去慢慢熟练,才会有真正收获。

    没有原书,也要网上找PDF来看。

    网上的原版资料多了去了,下载东西也到原始下载点去看看。

    你会知其所以然,呵呵。

    ***********************************************/

  • 相关阅读:
    python 自定义去掉空行
    JavaScript 获取时间函数
    python 自定义ssh
    python 去掉空行
    python roboot解析 output.xml
    语音识别-windows
    python 自定义request模块调试
    python 自定义装饰器
    python 自定义Server酱模块编写
    python 自定义exception模块
  • 原文地址:https://www.cnblogs.com/dpblue/p/3946964.html
Copyright © 2020-2023  润新知