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 fortunato at 2008-01-22 11:00:26 on Problem 1047
#include<iostream>
#include<string>
#include <algorithm>
using namespace std;
int isequel(char c[],int b[],int len)
{
	for(int i=0;i<len;i++)
	{
		if(b[i]!=c[i]-48)
			return 0;
	}
	return 1;
}
void main()
{
	char c[61];
	int t[61];
	while(cin>>c)
	{
		int len=strlen(c);
		int a[61];
		
		for(int i=0;i<len;i++)
		{
			t[i]=c[i]-48;
			a[i]=t[i];
		}

		sort(c,c+len);
		int k=1;
		for(;k<len;k++)
		{
			int b[61]={0};
			for(int j=len-1;j>=0;j--)
			{
				int temp=a[j]+t[j];
//				if(j>=0)
//					temp+=b[j];
//				cout<<temp<<endl;
				b[j]+=temp%10;
				b[j-1]=temp/10;			
				if(b[j]>9)
				{
					b[j-1]+=b[j]/10;
					b[j]=b[j]%10;					
				}			
				t[j]=b[j];
			}
//			for(int v=0;v<len;v++)
//				cout<<t[v];
//			cout<<endl;
			sort(b,b+len);
			if(!isequel(c,b,len))
			{
				break;
			}
		}
		if(k==len)
		{
			for(int r=0;r<len;r++)
				cout<<a[r];
			cout<<" is cyclic"<<endl;
		}
		else
		{
			for(int r=0;r<len;r++)
				cout<<a[r];
			cout<<" 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