View Code of Problem 5

#include<stdio.h>  

int max (int p[],int a)
{
	int n=0,i,j,f;
	for (i=0;i<a-1;i++)
		for (j=1;j<a;j++)
		{
			if (p[i]>n)
			{
				n=p[i];
				f=i;
			}
			if (n<p[j])
			{
				f=j;
				n=p[j];
		}
		}
	return f;
}

int main ()
{
	int t,i,j,a[50],b[50],o[50],p[50];
	scanf("%d",&t);
	for (i=0;i<t;i++)
	{
		int n,m;
		scanf("%d%d",&n,&m);
		o[i]=m;
		p[i]=n;
		for (j=0;j<n;j++)
			scanf("%d%d",&a[j],&b[j]);
	}
	int c[50],s[50];
	for (i=0;i<t;i++)
	{
		for (j=0;j<p[i];j++)
			s[j]=a[j]*10000+b[j];
		for (j=0;j<o[i];j++)
		{
			c[j]=max(s,p[i]);
			s[c[j]]=0;
		}
		for (j=0;j<o[i];j++)
			printf("%d ",c[j]+1);
		printf("\n");
	}
	return 0;
} 

Double click to view unformatted code.


Back to problem 5