Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
和1001差不多去掉优化就对了。所有1。。。n都要运算,不能满足了就break; 如111111111 is cyclic 1111111111 is not cyclic #include <iostream> #include <string.h> #include <cmath> using namespace std; int main() { char num[61]; int cyc[61],bt[61],p[61]; int i,j,k,s,len,m; bool fl; while(scanf("%s",num)!=EOF) { m=0; len=strlen(num); for(i=0;i<len;i++) { cyc[i]=num[i]-'0'; bt[i]=cyc[i]; p[i]=bt[i]; } for(i=0;i<len;i++) { for(j=1;j<=len;j++) { fl=false; for(k=0;k<len;k++) p[k]=p[k]*j; for(k=len-1;k>0;k--) { p[k-1]+=p[k]/10; p[k]=p[k]%10; if(p[k]!=cyc[k]) {fl=true;break;} } if(p[0]>=10) {m=-1;break;} if(p[0]<10&&k==0&&fl==false) { m++; } for(k=0;k<len;k++) p[k]=bt[k]; } if(p[0]>=10) break; s=cyc[len-1]; for(k=len-2;k>=0;k--) cyc[k+1]=cyc[k]; cyc[0]=s; } for(i=0;i<len;i++) printf("%d",bt[i]); if(m==len) printf(" is cyclic\n"); else printf(" is not cyclic\n"); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator