题目链接:http://bailian.openjudge.cn/practice/2952/
#include <cstdio> #include <cstring> char buf[70]; char next[70][70]; int L; bool isLoop2(int k){ bool isLoop = true; int i = 0; while(i < L){ isLoop = true; for(;i < L && buf[i] != next[k][0];i++); if(i == L)return false; for(int j = 0,p = i;j < L;j++,p++){ if(buf[p % L] != next[k][j]){isLoop = false;break;} } if(isLoop)return true; i++; } return false; } bool isLoop(int k){ bool isLoop; for(int i = 0;i < L;i++){ isLoop = true; if(buf[i] == next[k][0]){ for(int j = 0,p = i;j < L;j++,p++){ if(buf[p % L] != next[k][j]){ isLoop = false;break; } } if(isLoop == true)return true; } } return false; } int main(){ scanf("%s",buf); L = strlen(buf); /*for(int j = 0;j < L;j++) printf("buf[%d] %d ",j,buf[j] - '0');*/ bool success = true; for(int j = 0;j < L;j++) next[0][j] = buf[j]; for(int i = 1;i < L;i++){ int carry = 0; for(int j = L-1;j >= 0;j--){ //printf("buf[%d] %d ",j,buf[j]); int t = carry + buf[j] -'0' + next[i-1][j] - '0'; next[i][j] = (t % 10) + '0'; carry = t /10; } // for(int j = 0;j < L;j++) // printf("%d",next[i][j] - '0'); // printf(" "); if(!isLoop(i)){success = false;break;} } if(success)printf("1 "); else printf("0 "); }