首页 > 代码库 > usaco-dualpal-pass
usaco-dualpal-pass
呵呵,这两道题相差不大:
/*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);}
测试用例:
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。