浙大PAT。。。不解释。。原来各个学校出题是这样出的,好吧。宿舍好冷,手全快冻的打不动字了
/* ID:linyvxi1 TASK:dualpal LANG:C++ */ #include <stdio.h> #include <string.h> #include <stdlib.h> int N,S; bool pal(int n,int b) { char str1[100]; char str2[100]; memset(str1,'\0',sizeof(str1)); memset(str2,'\0',sizeof(str2)); int i=0,j=0; while(n){ if(n%b>=10) str1[i]=n%b-10+'A'; else str1[i]=n%b+'0'; n/=b; i++; } for(i=strlen(str1)-1;i>=0;i--){ str2[j]=str1[i]; j++; } if(strcmp(str1,str2)==0) return true; return false; } int check(int n) { int i,tim=0; for(i=2;i<=10;i++){ if(pal(n,i)) tim++; } return tim; } int main() { FILE* fin=fopen("dualpal.in","r"); FILE* fout=fopen("dualpal.out","w"); fscanf(fin,"%d%d",&N,&S); int i=S+1,cou=0; while(1){ if(cou==N) break; if(check(i)>=2){ cou++; fprintf(fout,"%d\n",i); } i++; } }
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