Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 10716 | Accepted: 4913 |
Description
Input
Output
Sample Input
142857 142856 142858 01 0588235294117647
Sample Output
142857 is cyclic 142856 is not cyclic 142858 is not cyclic 01 is not cyclic 0588235294117647 is cyclic
post code:原字符串赋值两次
然后 在每次生成的新的字符串中进行查找,如果木有找到 就跳出 返回失败
首先先 将
#include<stdio.h> #include<string.h> char temp[100]; char sample[100]; char ch[200]; int num[100],len; int add() //add 使字符串相加 { int i,carry=0; for(i=len-1;i>=0;i--) { temp[i]+=num[i]+carry; if(temp[i]>'9'){ carry=1; temp[i]-=10; } else carry=0; } return carry; } int main() { int i,judge; char *pos; while(scanf("%s",temp)!=EOF) { len=strlen(temp); strcpy(ch,temp); // ch 进行判断 将原字符串链接到后面 strcat(ch,temp); strcpy(sample,temp); //sample 保存原字符 for(i=0;i<len;i++) { num[i]=temp[i]-'0'; } for(i=1;i<len;i++) { judge=add(); //进行叠加 *1就可以忽略了 一定可以 if(judge==1)break; else { pos=NULL; pos=strstr(ch,temp); //先查找 如果找到就可以了 if(pos==NULL)break; } } if(i==len)printf("%s is cyclic\n",sample); //进行了n次 每次都能找到就可以了 else printf("%s is not cyclic\n",sample); //木有找到 } }