1047

/*
算是个模拟题吧
*/

// include file
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <ctime>

#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <bitset>

#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <list>
#include <functional>

using namespace std;

// typedef
typedef __int64 LL;

// 
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)

#define Z(a,b) ((a)<<(b))
#define Y(a,b) ((a)>>(b))

const double eps = 1e-6;
const double INFf = 1e100;
const int INFi = 1000000000;
const LL INFll = (LL)1<<62;
const double Pi = acos(-1.0);

template<class T> inline T sqr(T a){return a*a;}
template<class T> inline T TMAX(T x,T y)
{
	if(x>y) return x;
	return y;
}
template<class T> inline T TMIN(T x,T y)
{
	if(x<y) return x;
	return y;
}
template<class T> inline T MMAX(T x,T y,T z)
{
	return TMAX(TMAX(x,y),z);
}
template<class T> inline T MMIN(T x,T y,T z)
{
	return TMIN(TMIN(x,y),z);
}
template<class T> inline void SWAP(T &x,T &y)
{
	T t = x;
	x = y;
	y = t;
}


// code begin
char in[70],out[70],mid[70];
int N;
void query(char *a,char *b)
{
	//a = a + b
	for(int i=N-1,j=0,k;i>=0;i--)
	{
		k = a[i]-'0'+b[i]-'0'+j;
		a[i] = k%10+'0';
		j = k/10;
	}
}
bool Isok(char *a,char *b)
{
	// a是否是b的一个变幻形式
	for(int i=0,k;i<N;i++)
	{
		k=0;
		for(int j=i;j<N;j++) mid[k++] = b[j];
		for(int j=0;j<i;j++) mid[k++] = b[j];
		mid[N] = 0;
		//printf(" %s\n",mid);
		if(strcmp(mid,a)==0) return true;
	}
	return false;
}
bool check(char *tar,int n)
{
	strcpy(out,tar);
	for(int i=1;i<n;i++)
	{
		query(out,tar);
		//printf("%s\n",out);
		if(!Isok(out,tar))
			return false;
	}
	return true;
}
int main()
{
	read;
	write;
	while(scanf("%s",in)==1)
	{
		N = strlen(in);
		if(check(in,N))
			printf("%s is cyclic\n",in);
		else
			printf("%s is not cyclic\n",in);
	}
	return 0;
}
posted @ 2011-04-30 21:03  AC2012  阅读(166)  评论(0编辑  收藏  举报