CCF201503(2)待优化

3/8/2017来源:ASP.NET技巧人气:984

AC~显然代码冗余待优化

#include<stdio.h>
struct index
{
	int key;
	int time;
}b[1001];
int main()
{
	int n,i,j,t;
	int count=0;
	int sum=0;
	int max=0;
	int a[1001];
	int book[1001]={0};
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		t=a[i];
		book[t]++;
		if(a[i]>max)
		max=a[i];
	}
	for(i=1;i<=max;i++)
	{
		if(book[i])
		{
			count++;
			sum=sum+book[i];
			b[count].key=i;
			b[count].time=book[i];
		}
		if(sum==n)
		break;
	}
	t=0;
	for(i=n;i>0;i--)
	{				 
			for(j=1;j<=count;j++)
			{
				if(b[j].time==i)
				{
					t=t+b[j].time;
					PRintf("%d %d\n",b[j].key,b[j].time);
					if(t<n)
					{
						continue;
					}
					else
						break;				
				}
			}		
	}		
	return 0;	
}