| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为什么老是WA?求给组测试数据!(Code)#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator