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?求给组测试数据!(Code)

Posted by huicpc27 at 2005-08-28 02:15:33 on Problem 2549
#include <iostream.h>
#include <stdlib.h>
#include <math.h>
/*

int cmp ( const void *a , const void *b ) 
{
	return *(int *)a - *(int *)b; 
} 
*/
void doRun()
{
	int i,j,k,l,n;
	long *a,temp;
	bool flag;
	while(cin>>n)
	{
		if(n == 0)
			return;
		a = new long[n];
		for(i=0;i<n;i++)
		{
			cin>>a[i];
		}
		//qsort(a,n,sizeof(a[0]),cmp);
		for(i=0;i<n-1;i++)
		{
			for(j=i+1;j<n;j++)
			{
				if(a[i]>a[j])
				{
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				}
			}
		}
		flag = false;
		temp = a[n-1];
		for(i=n-1;i>=3;i--)
		{
			for(j=0;j<i;j++)
			{
				for(k=j+1;k<i;k++)
				{
					for(l=k+1;l<i;l++)
					{
						if(a[i] == a[j]+a[k]+a[l])
						{
							flag = true;
							temp = a[i];
							goto loop;
						}
					}
				}
			}
		}
loop:	if(flag)
			cout<<temp<<endl;
		else
			cout<<"no solution"<<endl;
	}
}


int main()
{
	doRun();
	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