poj 1047 Round and Round We Go

来源:互联网 发布:神经网络算法知乎 编辑:程序博客网 时间:2024/05/22 11:30

简单的高精度模拟。

 

#include <iostream>#include <cstdio>#include <cstring>using namespace std;int main(){    char s[200],sc[200];    while(scanf("%s",s)!=EOF)    {        int len=strlen(s),flag=1,i,j,k=0;        for(i=1; i<=len; i++)        {            memset(sc,0,sizeof(sc));            int c=0,r=0;            for(j=len-1; j>=0; j--)            {                r=(s[j]-'0')*i+c;                sc[j]=r%10+'0';                c=r/10;            }            //cout<<sc<<endl;            if(c!=0)            {                flag=0;                break;            }            for(k=0; k<len; k++)            {                if(strcmp(s,&sc[k])==0) break;                else sc[k+len]=sc[k];            }            if(k>=len)            {                flag=0;                break;            }        }        if(flag) cout<<s<<" is cyclic"<<endl;        else cout<<s<<" is not cyclic"<<endl;    }    return 0;}


 

0 0
原创粉丝点击