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.h> template<class T> void insertsort(T data[],int n) { for(int i=1,j;i<n;i++) { T tmp=data[i]; for(j=i;j>0&&tmp<data[j-1];j--) data[j]=data[j-1]; data[j]=tmp; } } int main() { int n,m,i,j,Time; cin>>n; for(i=0;i<n;i++) { Time=0; cin>>m; int *num=new int [m]; for(j=0;j<m;j++) cin>>num[j]; insertsort(num,m); --m; while(m>3) { Time=Time+num[m]+num[0]+2*num[1]; m-=2; } if(m==0) Time=Time+num[0]; else if(m==1) Time=Time+num[1]; else if(m==2) Time=Time+num[0]+num[1]+num[2]; else if(m==3) Time=Time+num[0]+3*num[1]+num[3]; cout<<Time<<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