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呢#include<iostream> using namespace std; int main() { int a[1000],n,s,b; s=0; cin>>n; int m=n; b=n; for(int i=0;i<n;i++) { cin>>a[i]; if(a[i]>100) exit(0); } if(n==1) { cout<<a[0]<<endl; cout<<a[0]<<endl; } else { for(int j=0;j<n-1;j++) for(int k=j+1;k<n;k++) { int temp; if(a[j]>a[k]) { temp=a[j]; a[j]=a[k]; a[k]=temp; } } if(n==2) { cout<<a[1]<<endl; cout<<a[0]<<" "<<a[1]<<endl; } else if(n==3) { s=a[0]+a[1]+a[2]; cout<<s<<endl; cout<<a[0]<<" "<<a[1]<<endl; cout<<a[0]<<endl; cout<<a[0]<<" "<<a[2]<<endl; } else { while(n>2) { s=s+a[0]+a[n-1]+2*a[1]; n=n-2; if(n==1) s=s-a[1]; if(n==2) s=s+a[1]; } cout<<s<<endl; while(m>2) { cout<<a[0]<<" "<<a[1]<<endl; cout<<a[0]<<endl; cout<<a[m-2]<<" "<<a[m-1]<<endl; cout<<a[1]<<endl; m=m-2; } if(b>1) cout<<a[0]<<" "<<a[1]<<endl; } } return s; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator