Posted on 2008-04-01 13:48
superman 阅读(217)
评论(0) 编辑 收藏 引用 所属分类:
ZOJ
1 /* Accepted 1073 C++ 00:00.02 848K */
2 #include <string>
3 #include <iostream>
4
5 using namespace std;
6
7 int main()
8 {
9 string s;
10 while(cin >> s)
11 {
12 int n = s.size();
13 bool cyclic = true;
14 for(int k = 2; k <= n; k++)
15 {
16 int c[200] = {0};
17 for(int i = n; i > 0; i--)
18 {
19 c[i] += (s[i - 1] - '0') * k;
20 c[i - 1] += c[i] / 10;
21 c[i] %= 10;
22 }
23
24 if(c[0])
25 {
26 cyclic = false;
27 break;
28 }
29
30 string cur;
31 for(int i = 1; i <= n; i++)
32 cur += (c[i] + '0');
33
34 int pos = 0;
35 while(true)
36 {
37 pos = cur.find(s[0], pos);
38 if(pos == string::npos)
39 {
40 cyclic = false;
41 break;
42 }
43
44 string tmp;
45 for(int i = pos; i < n; i++)
46 tmp += cur[i];
47 for(int i = 0; i < pos; i++)
48 tmp += cur[i];
49
50 if(tmp == s)
51 break;
52
53 pos++;
54 }
55 }
56 if(cyclic)
57 cout << s << " is cyclic" << endl;
58 else
59 cout << s << " is not cyclic" << endl;
60 }
61
62 return 0;
63 }
64