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 |
请哪位高手帮忙看一下,为什么老是wrong answer???????#include<iostream> using namespace std; int a[30]; int main() { int N; while(cin>>N) { if(N==0) break; int i,j, Esum=0,Ssum=0; for( i=0;i<N;i++) cin>>a[i]; i=0,j=N-i-1; for( ;i<j;) { if(Ssum<Esum) { Ssum=Ssum+a[i]; i=i+1; } else if(Ssum>Esum) { Esum=Esum+a[j]; j--; } else if(Ssum==Esum) { Ssum=Ssum+a[i]; Esum=Esum+a[j]; i++; j--; } } if((i==j)&&(Esum<Ssum)) { Esum=Esum+a[j]; i--; } else if((i==j)&&(Esum>=Ssum)) { Ssum=Ssum+a[i]; j++; } if(Ssum==Esum) cout<<"Sam stops at position "<<(i+1)<<" and Ella stops at position "<<(j+1)<<"."<<endl; else cout<<"No equal partitioning."<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator