Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

怎一个水字了得。

Posted by 0943041192 at 2011-02-12 13:43:19 on Problem 1047
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string str;
	int i,j,k,length,sum,num[65];
	while (cin>>str)
	{
		length = str.size();
		for ( i = 0 , sum = 0 ; i < length ; i++)
		{
			sum += str[i]-48;
		}
		if( sum == 0 )	
			cout<<str.c_str()<<" is cyclic"<<endl;
		else if( sum * 2 != 9 * length )
			cout<<str.c_str()<<" is not cyclic"<<endl;
		else
		{
			//需要判断顺序是否满足
			for ( i = 0 ; i < length ; i++)
			{
				num[i] = (str[i]-48)*(length+1);
			}
			//进位。
			for ( i = length-1 , j = 0 ; i >= 0 ; i--)
			{
				k = num[i]+j;
				j = k/10;
				num[i] = k%10;
				if( num[i] != 9 )	break;
			}
			if( i == -1 && j == 0 )
				cout<<str.c_str()<<" is cyclic"<<endl;
			else
				cout<<str.c_str()<<" is not cyclic"<<endl;
		}
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator