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

做这种题目一向是义无反顾地超时,大牛们告诉我怎么优化吧

Posted by 00448175 at 2005-04-29 22:24:00 on Problem 2418
#include<iostream.h>
#include<string.h>
#include<iomanip.h>
#include<stdlib.h>
char tree[1000000][30];
int count[10000];
int compare(const void *a,const void *b){
	return(strcmp((char*)a,(char*)b));
}
int cmp(char *a,char *b){
	for(int i=0;*(a+i)!='\0'||*(b+i)!='\0';i++)
		if(*(a+i)!=*(b+i))return 0;
	return 1;
}
void main()
{
	int i=0,j=0;
	while(cin.getline(tree[i],30))
		i++;
	
//	cout<<i<<endl;	
	qsort(tree,i,sizeof(tree[0]),compare);

	double num=0;
	int tem=0;

	for(j=0;j<i+1;j++){
		if(cmp(tree[tem],tree[j])==0){
			cout<<tree[tem]<<" ";
			cout<<setiosflags(ios::fixed);
			cout<<setprecision(4)<<(100*num/(i))<<endl;
			tem=j;
			num=1;
			continue;
		}
		num++;
	}
}

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