usaco-dualpal-pass

呵呵,这两道题相差不大:

/*
ID: qq104801
LANG: C++
TASK: dualpal
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

/* for debug only:counter
*/
void debug_dummy(void)
{
    return;
}

int n,s;
char x[32];
char num[]={'0','1','2','3','4','5','6','7','8','9'};

void xnum(int a,int b)
{
    int i=0;
    int c=a;
    while(c!=0)
    {
        x[i]=num[c%b];
        c=c/b;
        i++;
    }
    x[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 count=0,jj;
    int i;
    i=s;
    while(i++)
    {
        jj=0;
        for(int j=2;j<=10;j++)  
        {      
            xnum(i,j);
            if (ispalindromes(x))
            {
                jj++;
                if (jj==2)
                {
                    fprintf(f,"%d\n",i);
                    //printf("%d %d %s\n",i,j,x);  
                    count++;
                    if (count>(n-1))
                        return;
                    break;  
                }
            }
        }
    }
}

main () {    
    FILE *fin = fopen ("dualpal.in", "r");
    FILE *fout = fopen ("dualpal.out", "w"); 
    fscanf(fin,"%d %d",&n,&s);
    //printf("%d\n",base);
    test(fout);
    fclose(fin);
    fclose(fout);
    exit (0);
}

测试用例:

USER: ll tom [qq104801]
TASK: dualpal
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.005 secs, 3496 KB]
   Test 2: TEST OK [0.003 secs, 3496 KB]
   Test 3: TEST OK [0.008 secs, 3496 KB]
   Test 4: TEST OK [0.008 secs, 3496 KB]
   Test 5: TEST OK [0.011 secs, 3496 KB]
   Test 6: TEST OK [0.011 secs, 3496 KB]
   Test 7: TEST OK [0.008 secs, 3496 KB]

All tests OK.

Your program ('dualpal') produced all correct answers! This is your submission #2 for this problem. Congratulations!

Here are the test data inputs:

------- test 1 ----
5 1
------- test 2 ----
9 10
------- test 3 ----
15 9900
------- test 4 ----
10 90
------- test 5 ----
12 125
------- test 6 ----
12 1900
------- test 7 ----
8 500

Keep up the good work!
Thanks for your submission!

 

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

导航