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]='\0';
    l=strlen(y);
    for(i=0;i<l;i++)
    {
        xx[i]=y[l-i-1];
    }
    xx[++i]='\0';
    //printf("%s  len:%d\n",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\n",y,x);
            //printf("%d %d\n",i,bb);
        }
    }
}

main () {    
    FILE *fin = fopen ("palsquare.in", "r");
    FILE *fout = fopen ("palsquare.out", "w"); 
    fscanf(fin,"%d",&base);
    //printf("%d\n",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!

 

说明理解了题意。

posted on 2014-08-30 22:13  深蓝无忌  阅读(143)  评论(0编辑  收藏  举报

导航