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 y05dzz at 2006-08-17 10:36:14 on Problem 2969
#include<iomanip.h>
#include<string.h>
int main()
{
	char s[1011];
//	while(cin>>s)
//	{
	cin>>s;
		int dig[10] = {0}, sum = 0,i,j;
		for (i = 0;i<(int)strlen(s); i++)
		{
			dig[s[i] - '0']++;
			sum += s[i] - '0';
		}
		if (dig[0]+dig[5] == 0)
		{
			cout<<"impossible"<<endl;
			return 0;
		}
		else
		{
///////////////////////////////////////////////////////////////
			if(dig[0]>0)
			{
				if(sum%3==0)
				{
					if(sum==0)
					{
						cout<<0<<endl;
					}
					else
					{
						for(i=9;i>=0;i--)
						{
							for(j=0;j<dig[i];j++)
							{
								cout<<i;
							}
						}
						cout<<endl;
					}
				}
				else
				{
					while(sum%3!=0)
					{
						for(i=0;i<=9;i++)
						{
							if(dig[i]>0&&((i-(sum%3))%3==0)&&(i>=(sum%3)))
							{
								dig[i]--;
								sum-=i;
								break;
							}
						}
						if(i>9)
						{
							for(j=1;j<=9;j++)
							{
								if(dig[j]>0)
								{
									dig[j]--;
									sum-=j;
									break;
								}
							}
						}
					}
					if(sum==0)
					{
						cout<<0<<endl;
					}
					else
					{
						for(i=9;i>=0;i--)
						{
							for(j=0;j<dig[i];j++)
							{
								cout<<i;
							}
						}
						cout<<endl;
					}
				}
			}			
			else
/////////////////////////////////////////////////////////////////////////
			{
				dig[5]--;
				if(sum%3==0)
				{
					for(i=9;i>=0;i--)
					{
						for(j=0;j<dig[i];j++)
						{
							cout<<i;
						}
					}
					cout<<5<<endl;
				}
				else
				{
					while(sum%3!=0)
					{
						for(i=0;i<=9;i++)
						{
							if(dig[i]>0&&((i-(sum%3))%3==0)&&(i>=(sum%3)))
							{
								dig[i]--;
								sum-=i;
								break;
							}
						}
						if(i>9)
						{
							for(j=1;j<=9;j++)
							{
								if(dig[j]>0)
								{
									dig[j]--;
									sum-=j;
									break;
								}
							}
						}
						if(sum==5)
						{
							cout<<"impossible"<<endl;
							break;
						}
					}
					if(sum!=5)
					{
						for(i=9;i>=0;i--)
						{
							for(j=0;j<dig[i];j++)
							{
								cout<<i;
							}
						}
						cout<<5<<endl;
					}
					
				}
			}
			
		}
//	}
	return 0;
}

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