/* ID: nenusb1 LANG: C TASK: dualpal */ #include <stdio.h> #include <string.h> char numStr[12]; int ifPal(){ int len = strlen(numStr); int i; for(i=0; i<len; i++){ if(numStr[i] != numStr[len-1-i]) return 0;//use break is stupid! } return 1; } //itoa void myItoa(int value, int base){ int i=0; while(pow(base,i)<=value){ i++; } int len = --i; numStr[len+1] = '\0'; char c[1]; while(value>=0 && i>=0){ int tmp = value % base; value /= base; //convert single int to char numStr[len-i] = tmp+'0'; i--; } } int main(){ freopen("dualpal.in","r",stdin); freopen("dualpal.out","w",stdout); int n, s; scanf("%d %d",&n,&s); int num, count; count = 0; for(num = s+1;count<n;num++){ memset(numStr,'0',sizeof(numStr)); int base; int palCount = 0; for(base = 2; base<=10; base++){ myItoa(num,base); if(ifPal(numStr)){ palCount++;} if(palCount == 2) {printf("%d\n", num); count++; break;} } } return 0; }
參考了http://blog.csdn.net/lisc741/article/details/8264840才AC.. .net
將原來的code
char numStr[12]
改爲了全局變量,以前的Execution error 就解決了, don't konw why
blog