POJ 1047 Round and Round We Go

http://poj.org/problem?id=1047

按照某大牛总结的一条规律,对于数N,若N为循环的则有N*(length(N)+1)=99....99, (length(N)个9),length(N)为N的位数,含前导0。应该还是简单的...

还有POJ是什么时候换网址的...= =b

#include<iostream>
#include<string>
using namespace std;
bool fun(string str)
{
	int n=str.length()+1;
	int i,up=0,temp=0;
	for(i=n-2;i>=0;i--)
	{
		temp=(int)(str[i]-'0');
		if((temp*n+up)%10!=9) return false;
		up=(temp*n+up)/10;
	}
	return true;
}
int main()
{
	string str1;
	while(cin>>str1)
	{
		if(fun(str1))
		{
			cout<<str1<<" is cyclic"<<endl; 
		}
		else
		{
			cout<<str1<<" is not cyclic"<<endl;
		}
	}
	return 0;
}

posted @ 2011-03-16 16:23  watana  阅读(356)  评论(0编辑  收藏  举报