-
//zoj1073 Round and Round We Go
-
// Accepted 1073 C++ 00:00.00 832K
-
#include <cstdio>
-
#include <iostream>
-
#include <string>
-
using namespace std;
-
char s[100],t[100];
-
int len;
-
void mult(int n)
-
{
-
int i,sum[100]={0};
-
for (i=0; i<len; ++i){
-
sum[i] = s[i]-'0';
-
sum[i] *= n;
-
}
-
for (i=len-1; i>0; --i){
-
if (sum[i]>9){
-
sum[i-1] += sum[i]/10;
-
sum[i] %= 10;
-
}
-
}
-
for (i=0; i<len; ++i)
-
t[i] = sum[i]+'0';
-
}
-
bool cyclic()
-
{
-
int i,j,flag[100]={0};
-
for (i=0; i<len; ++i)
-
for (j=0; j<len; ++j)
-
if (!flag[j] && s[i]==t[j]){
-
flag[j] = 1;
-
break;
-
}
-
for (i=0; i<len; ++i)
-
if (!flag[i]) return false;
-
return true;
-
}
-
void solve()
-
{
-
len = strlen(s);
-
for (int n=2; n<=len; ++n){
-
mult(n);
-
if (!cyclic()){
-
cout << s << " is not cyclic" << endl;
-
return;
-
}
-
}
-
cout << s << " is cyclic" << endl;
-
}
-
int main()
-
{
-
#ifdef ONLINE_JUDGE
-
#else
-
freopen("1073.txt","r",stdin);
-
#endif
-
while (cin >> s)
-
solve();
-
#ifdef ONLINE_JUDGE
-
#else
-
fclose(stdin);
-
#endif
-
return 0;
-
}
zoj1073 Round and Round We Go
最新推荐文章于 2022-03-12 15:44:34 发布
本文介绍了一个用于判断一个数是否为循环数的算法实现。通过字符串操作和比较来验证当一个数乘以特定倍数时,其结果是否仍由原始数字的循环排列组成。此算法适用于数值分析和数学竞赛。
896

被折叠的 条评论
为什么被折叠?



