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

Re:为什么会出现 runtime error 帮帮忙,看看!!

Posted by chentan at 2009-05-16 23:00:21 on Problem 2418
In Reply To:为什么会出现 runtime error 帮帮忙,看看!! Posted by:xhu_li at 2009-01-11 22:05:16
> 为什么会出现  runtime error 帮帮忙,看看!!
> 
> #include<stdio.h>
> #include<string.h>
> #include<math.h>
> struct tree
> {
> 	char name[35];
> 	double per;
> };
> struct tree str[10000];
> int b[10000],t;
> int f(char *s)
> {
> 	int i;
> 	for(i=0;i<t;i++)
> 	{
> 		if(strcmp(str[i].name,s)==0)
> 			return i;
> 	}
> 	strcpy(str[t].name,s);
> 	t++;
> 	return t-1;
> }
> void q_sort(struct tree s[],int left,int right)
> {
> 	int low,upper;
> 	struct tree temp;
> 	struct tree temp1;
> 	if(left<right)
> 	{
> 		temp=s[left];
> 		low=left;
> 		upper=right+1;
> 	}
> 	while(1)
> 	{
> 		while(strcmp(s[++low].name,temp.name)<0);
> 		while(strcmp(s[--upper].name,temp.name)>0);
> 		if(low>=upper)
> 		{
> 			break;
> 		}
> 		temp1=s[low];
> 		s[low]=s[upper];
> 		s[upper]=temp1;
> 	}
> 	s[left]=s[upper];
> 	s[upper]=temp;
> 	q_sort(str,left,upper-1);
> 	q_sort(str,upper+1,right);
> 
> }
> 
> void main()
> {
> 	char s[35];
> 	int i,n;
> 	long count=0;
> 	memset(b,0,sizeof(b));
> 	t=0;
> 	while(gets(s)!=NULL)
> 	{
> 		count++;
> 		n=f(s);
> 		b[n]++;
> 	}
> 	for(i=0;i<t;i++)
> 	{
> 		str[i].per=b[i]*1.0/count;
> 	}
> 	q_sort(str,0,t);
> 	for(i=0;i<t;i++)
> 		printf("%s %.4lf\n",str[i].name,str[i].per*100);
> }

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