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 |
为什么会Memory Limit Exceed?高手们请帮忙改进一下#include<iostream.h> #include<string.h> void main(){ char **p,t[8]=""; int i,j,n,len,sum,min,max; int* a; int* b; while(cin>>n,n!=-1){ sum=0; b=new int[n]; p=new char*[n]; for(i=0;i<n;i++){ b[i]=1; a=new int[3]; for(j=0;j<3;j++){ cin>>a[j]; b[i]=b[i]*a[j]; } cin>>t; len=strlen(t); *(p+i)=new char[len]; strcpy(*(p+i),t); } for(i=0;i<n;i++){ sum=sum+b[i]; } sum=sum/n; for(i=0;i<n;i++){ if(b[i]<sum) min=i; if(b[i]>sum) max=i; } cout<<*(p+max)<<" took clay from "<<*(p+min)<<"."<<endl; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator