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

why WA,can someone help?

Posted by tanzhangwen at 2008-11-16 15:01:43 on Problem 2418
thank you 

//code as follow

#include <iostream>
using namespace std;
#define N 10005
#define M 35
char tree[N][M],num[N];
int nindex;
void insert(char *s)
{
	int low=0;
	int up=nindex-1;
	int i,mid;
	while(low<=up){
		mid=(low+up)>>1;
		if(strcmp(tree[mid],s)==0){
			num[mid]++;
			return ;
		}
		else if(strcmp(tree[mid],s)<0)
			low=mid+1;
		else 
			up=mid-1;
	}
	for(i=nindex;i>low;i--)
	{
		strcpy(tree[i],tree[i-1]);
		num[i]=num[i-1];
	}
	strcpy(tree[low],s);
	num[low]=1;
	nindex++;
}
int main()
{
//	freopen("a.txt","r",stdin);
	int n,i;
	char s[M];
	nindex=0;
	n=0;
	while(gets(s))
	{
		n++;
		insert(s);
	}
	for(i=0;i<nindex;i++)
		printf("%s %.4f\n",tree[i],num[i]*100/(double)n);
	return 0;
}

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