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……是不是因为数组开得不够?

Posted by acm_pku at 2007-07-29 14:15:00 on Problem 3297
#include "stdio.h"
#include "string.h"
char s1[10100][100];
void sort(int *d,int *a,int n)
{
	int i,j,t;
	for(i=1;i<=n;i++)
		d[i]=i;
	for(i=1;i<=n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			if(a[d[i]]<a[d[j]])
			{
				t=d[i];
				d[i]=d[j];
				d[j]=t;
			}
		}
	}
}
void sort1(int *f,int n)
{
	int i,j,k,t;
	for(i=0;i<=n;i++)
		f[i]=i;
	for(i=0;i<=n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			for(k=0;s1[f[i]][k]&&s1[f[j]][k];k++)
			{
				  if(s1[f[i]][k]>s1[f[j]][k])
				{
				   t=f[i];
				   f[i]=f[j];
				   f[j]=t;
				   break;
				}
		        else if(s1[f[i]][k]<s1[f[j]][k])
					break;
			}
			if(s1[f[j]][k]==0)
			{
				t=f[i];
				f[i]=f[j];
				f[j]=t;
			}
		}
	}
}
int main()
{
	int i,j,k,p,q,cur,h;
	char s[10100][100];
    int b[1000];
	int d[1000];
	int f[1000];
	int count[1000];
	int tag1[1000];
	int tag2[1000];
	k=0;
	gets(s[0]);
	while(strcmp(s[k],"0")!=0)
	{
	while(strcmp(s[k],"1")!=0)
		gets(s[++k]);
	p=0;
	for(i=0;i<k;i++)
	{
		if(s[i][0]>=65&&s[i][0]<=90)
		{
			b[++p]=i;
		}
	}
	b[p+1]=k;
	for(i=0;i<k;i++)
	{
		tag1[i]=1;
		tag2[i]=1;
	}
	for(i=0;i<k;i++)
	{
		for(j=0;j<k;j++)
		{
			if(strcmp(s[i],s[j])==0)
			{
				if(i!=j)
				{
					
					for(q=i+1;q<j;q++)
					{
						if(s[q][0]>=65&&s[q][0]<=90)
						{
							tag1[i]=0;
							tag1[j]=0;
							break;
						}
					}
					if(q==j)
					{      
						tag2[j]=0;
					}
				}
			}
		}
	}
	for(i=1;i<=p;i++)
	{
		count[i]=0;
		for(j=b[i]+1;j<b[i+1];j++)
		{
			if(tag1[j])
			{
				if(tag2[j])
                   count[i]++;
			}
		}
	}
	sort(d,count,p);
	for(i=1;i<=p;)
	{
		q=0;
	    cur=i;
		k=count[d[i]];
		strcpy(s1[0],s[b[d[i]]]);
		for(j=i+1;j<=p;j++)
		{
			if(count[d[j]]==k)
            {
				q++;
				strcpy(s1[q],s[b[d[j]]]);
			}
			else
			{
				i=j;
				break;
			}
		}
		if(j>p)
			i=j;
		if(q>0)
		{
		sort1(f,q);
		for(j=0;j<=q;j++)
            printf("%s %d\n",s1[f[j]],count[d[cur]]);
		}
		else
			printf("%s %d\n",s[b[d[cur]]],count[d[cur]]);

	}
	k=0;
	gets(s[0]);
	}
	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