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

谢谢,不过我一改用print就变成runtime error了,真搞不懂(看看我的程序吧)

Posted by 00448175 at 2005-04-30 00:43:33 on Problem 2418
In Reply To:Re:呜呜呜,优化了以后还是超时,哪位大虾指点下? Posted by:frkstyc at 2005-04-30 00:07:18
#include<iostream.h>
#include<string.h>
#include<iomanip.h>
#include<stdlib.h>
#include<stdio.h>
char tree[1000000][30];
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,k=0;
	while(cin.getline(tree[i],30))
		i++;
	qsort(tree,i,sizeof(tree[0]),compare);
	double num=1;
	double jump=0.5;
	for(j=0;j<i;){
		for(k=0;;k++){
			jump*=2;
			if(cmp(tree[j],tree[j+int(jump)])==1)
				continue;
			else break;
		}
		if(jump==1){
			double r=100*num/i;
			printf("%s %3.4f \n",tree[j],r);
			j++;
			jump=0.5;
			num=1;
			continue;
		}
		num+=int(jump/2);
		j+=int(jump/2);
		jump=0.5;
	}
}


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