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 00448322 at 2005-03-09 14:13:38 on Problem 1014
#include <iostream.h>

int divide(int* num,int sum);
int i,j,k;

void main()
{
	int count=1;
	int num[6];
	while(1)
	{
		int sum=0,sum0=0;
		for(i=0;i<6;i++)
		{	
			cin>>num[i];
			sum=sum+(num[i]%2)*(i+1);
			sum0=sum+num[i];
		}
		if(sum0==0)
			break;
		else
		{
			cout<<"Collection #"<<count<<":"<<endl;
			if(divide(num,sum)==1)
				cout<<"Can be divided."<<endl;
			else
				cout<<"Can't be divided."<<endl;
			cout<<endl;
			count++;
		}
	}
}

int divide(int* num,int sum)
{
	if(sum%2==1)
		return(0);
	else
	{
		for(i=0;i<6;i++)
		{
			if(num[i]*(i+1)==sum/2)
				return(1);
		}
		for(i=0;i<5;i++)
		{
			for(j=i+1;j<6;j++)
				if(num[i]*(i+1)+num[j]*(j+1)==sum/2)
					return(1);
		}
		for(i=0;i<4;i++)
		{
			for(j=i+1;j<5;j++)
			{
				for(k=j+1;k<6;k++)
					if(num[i]*(i+1)+num[j]*(j+1)+num[k]*(k+1)==sum/2)
						return(1);
			}
		}
		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