Usaco-dualpal-pass

Source: Internet
Author: User

The two questions are not quite different:

/*ID: qq104801LANG: 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);}

Test cases:

USER: ll tom [qq104801]TASK: dualpalLANG: C++Compiling...Compile: OKExecuting...   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 500Keep up the good work!Thanks for your submission!

 

Usaco-dualpal-pass

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.