Round and Round We Go

http://acm.hdu.edu.cn/showproblem.php?pid=1313

考查大整数与小整数相乘

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #define N 70
 6 using namespace std;
 7 int main()
 8 {
 9     char str[N],a[N][N];
10     int len,i,j,flag,m;
11     while(gets(str))
12     {
13         memset(a,0,sizeof(a));
14 
15         printf("%s ",str);
16 
17         flag=0;
18 
19         len=strlen(str);
20 
21         strrev(str);
22 
23         for(i=0;i<len;i++)
24         {
25             for(j=0;j<len;j++)
26                 a[i][j]='0';
27             for(j=0;j<len;j++)
28             {
29                 m=a[i][j]-'0'+(i+1)*(str[j]-'0');//不能直接将m代入下面,因为a[i][j+1]使j的值发生变化;
30                 a[i][j]=(m)%10+'0';
31                 a[i][j+1]=(m)/10+'0';
32             }
33             a[i][j]='';
34 
35         }
36         sort(str,str+len);
37 
38         for(i=0;i<len;i++)
39         {
40             sort(a[i],a[i]+len);
41             if(strcmp(a[i],str)==0)
42                     flag++;
43         }
44         if(flag==len)
45             printf("is cyclic
");
46         else
47             printf("is not cyclic
");
48     }
49     return 0;
50 }
原文地址:https://www.cnblogs.com/zhengguiping--9876/p/4342865.html