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

这个程序感觉都对,也测试了数据,但都以WA出错,怎么回事???

Posted by E10614013 at 2008-07-14 16:05:43 on Problem 1014
#include<iostream>
using namespace std;
int main()
{
	int a[6],sum,p=0;
	int i,flag;
	for(i=0;i<6;i++)
		cin>>a[i];
	while(a[0]||a[1]||a[2]||a[3]||a[4]||a[5])
	{
		p++;
		sum=1*a[0]+2*a[1]+3*a[2]+4*a[3]+5*a[4]+6*a[5];
		if(sum%2!=0)
			cout<<"Collection #"<<p<<":"<<endl<<"Can't be divided."<<endl<<endl;
		else
		{
			 flag=1;
			if(a[5]%2!=0)
			{
				if(a[0]&&a[4])
				{
					a[0]=a[0]-1;
					a[4]=a[4]-1;
				}
				else 
				{
					if(a[1]&&a[3])
					{
						a[1]=a[1]-1;
						a[3]=a[3]-1;
					}
					else 
					{
						if((a[2]-2)>=0)
						{
							a[2]=a[2]-2;
						}
						else 
						{
							if((a[1]-3)>=0)
							{
								a[1]=a[1]-3;
							}
							else 
							{
								if((a[0]-2)>=0&&(a[1]-2)>=0)
								{
									a[0]=a[0]-2;
									a[1]=a[1]-2;
								}
								else 
								{
									if(a[0]&&a[1]&&a[2])
									{
										a[0]=a[0]-1;
										a[1]=a[1]-1;
										a[2]=a[2]-1;
									}
									else 
									{
										if((a[0]-2)>=0&&a[3])
										{
											a[0]=a[0]-2;
											a[3]=a[3]-1;
										}
										else 
										{
											if((a[0]-3)>=0&&a[2])
											{
												a[1]=a[1]-3;
												a[2]=a[2]-1;
											}
											else 
											{
												if((a[0]-4)>=0&&a[1])
												{
													a[0]=a[0]-4;
													a[1]=a[1]-1;
												}
												else 
												{
													if((a[0]-6)>=0)
													{
														a[0]=a[0]-6;
													}
													else
													{
														flag=0;
														cout<<"Collection #"<<p<<":"<<endl<<"Can't be divided."<<endl<<endl;
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
			if(a[4]%2!=0)
			{
				if(a[0]&&a[3])
				{
					a[0]=a[0]-1;
					a[3]=a[3]-1;
				}
				else 
				{
					if(a[1]&&a[2])
					{
						a[1]=a[1]-1;
						a[2]=a[2]-1;
					}
					else
					{
						if((a[0]-2)>=0&&a[2])
						{
							a[0]=a[0]-2;
							a[2]=a[2]-1;
						}
						else
						{
							if((a[0]-3)>=0&&a[1])
							{
								a[0]=a[0]-3;
								a[1]=a[1]-1;
							}
							else
							{
								if((a[1]-2)>=0&&a[0])
								{
									a[0]=a[0]-1;
									a[1]=a[1]-2;
								}
								else
								{
									if((a[1]-5)>=0)
									{
										a[1]=a[1]-5;
									}
									else
									{
										flag=0;
										cout<<"Collection #"<<p<<":"<<endl<<"Can't be divided."<<endl<<endl;
									}
								}
							}
						}
					}
				}
			}
			if(a[3]%2!=0)
			{
				if(a[0]&&a[2])
				{
					a[0]=a[0]-1;
					a[2]=a[2]-1;
				}
				else 
				{
					if((a[1]-2)>=0)
					{
						a[1]=a[1]-2;
					}
					else
					{
						if((a[0]-2)>=0&&a[1])
						{
							a[0]=a[0]-2;
							a[1]=a[1]-1;
						}
						else
						{
							if((a[0]-4)>=0)
							{
								a[0]=a[0]-4;
							}
							else
							{
								flag=0;
								cout<<"Collection #"<<p<<":"<<endl<<"Can't be divided."<<endl<<endl;
							}
						}
					}
				}
			}
			if(a[2]%2!=0)
			{
				if(a[0]&&a[1])
				{
					a[0]=a[0]-1;
					a[1]=a[1]-1;
				}
				else
				{
					if((a[0]-3)>=0)
					{
						a[0]=a[0]-3;
					}
					else
					{
						flag=0;
						cout<<"Collection #"<<p<<":"<<endl<<"Can't be divided."<<endl<<endl;
					}
				}
			}
			if(a[1]%2!=0)
			{
				if((a[0]-2)>=0)
					a[0]=a[0]-2;
				else
				{
					flag=0;
					cout<<"Collection #"<<p<<":"<<endl<<"Can't be divided."<<endl<<endl;
				}
			}
			if(flag==1)
				cout<<"Collection #"<<p<<":"<<endl<<"Can be divided."<<endl<<endl;
		}
		for(i=0;i<6;i++)
			cin>>a[i];
	}
		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