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 |
哪位大哥帮忙看一下,我的 程序错在哪儿,怎么就老通不过!本人将感激不禁!#include <iostream> using namespace std; void sort(int array[],int n) {int i,j,k,t; for(i=0;i<n-1;i++) {k=i; for(j=i+1;j<n;j++) if(array[j]<array[k]) k=j; t=array[k];array[k]=array[i];array[i]=t; } } int time_oushu(int array[],int n) {int t=0; if(n==2) t=array[1]; else t=array[0]+2*array[1]+array[n-1]+time_oushu(array,n-2); return t; } int time_jishu(int array[],int n) {int t; if(n==1)t=array[0]; else if(n==3)t=array[0]+array[1]+array[2]; else t=array[0]+2*array[1]+array[n-1]+time_jishu(array,n-2); return t; } void main() { int a[1000];int t,n,T,i=0; cin>>T; if(T>0&&T<=20){ while(T--){ cin>>n; if(n>1000) return ; for(i=0;i<n;i++) {cin>>a[i]; if(a[i]>=100) return;} sort(a,n); if(n%2)t=time_jishu(a,n); else t=time_oushu(a,n); cout<<t<<endl; } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator