#include <iostream>
#include <cstring>
#define MAX 60
using namespace std;
//两个数相加
int Add(int nMaxLen, int *a1, int *a2)
{
int nHighestPos = 0;
for(int i = 0; i <= nMaxLen - 1; ++i)
{
a1[i] += a2[i];
if(a1[i] >= 10)
{
a1[i] -= 10;
a1[i + 1]++;
}
if(a1[i + 1])
nHighestPos = i + 1;
}
return nHighestPos;
}
int main()
{
char *s1 = new char[MAX + 10]();
char *s2 = new char[MAX + 10]();
char *sDouble = new char[MAX + 10]();
int *a1 = new int[MAX + 10]();
int *a2 = new int[MAX + 10]();
while(cin >> s1)
{
int nLen1 = strlen(s1);
for(int i = nLen1 - 1, j = 0; 0 <= i; --i)
{
a1[j] = s1[i] - '0';
a2[j++] = s1[i] - '0';
}
strcpy(sDouble, s1);
strcat(sDouble, s1);
bool bOk = true;
for(int i = 0; i < nLen1 - 1; ++i)//注意这里一共计算nLen - 1个,不算第一个即原始的a1(a1 * 1)
{
int Pos = Add(nLen1, a1, a2);
if(Pos >= nLen1)
{
bOk = false;
break;
}
for(int i = nLen1 - 1, k = 0; 0 <= i; --i)
{
s2[k++] = a1[i] + '0';
}
for(int i = 0; i < nLen1; ++i)
if(strstr(sDouble, s2) == NULL)
{
bOk = false;0101
break;
}
}
if(bOk)
cout << s1 << " is cyclic" << endl;
else
cout << s1 << " is not cyclic" << endl;
}
delete [] s1;
delete [] s2;
delete [] a1;
delete [] a2;
delete [] sDouble;
return 0;
}
循环数的确定
最新推荐文章于 2022-12-25 11:26:06 发布