View Code of Problem 5

#include<stdio.h>
int main()
{
	int t;
	int x;

	scanf("%d",&t);
	while(t>0)
	{
		int n,m;
		scanf("%d%d",&n,&m);
		
		int apple[1000];
		int orgin[1000];
		
		//输入苹果和梨,共有n组数据; 
		int i;
		for(i=0;i<n;i++)
		{
			scanf("%d%d",&apple[i],&orgin[i]);
		}
		
		//
		while(m>0)
		{
			int maxapp=0;
			for(i=1;i<n;i++)
			{
				if(apple[i]>apple[maxapp])
				{
					maxapp=i;
				}
				else if(apple[i]==apple[maxapp])
				{
					if(orgin[i]>orgin[maxapp])
						maxapp=i;
				}				
			}
			if(m==1)
				printf("%d",maxapp+1);
			else 
				printf("%d ",maxapp+1);
			apple[maxapp]=0;
			orgin[maxapp]=0;
			
			m--;
		}
		printf("\n");
		
		t--;
	}
	
	
	
	return 0;
}

Double click to view unformatted code.


Back to problem 5