Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么会Memory Limit Exceed?高手们请帮忙改进一下

Posted by Alex at 2004-05-15 11:50:55 on Problem 1547
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator