View Code of Problem 5

#include<stdio.h>
void main()
{
	int t;
	int m, n;
	int a, b;
	int i, j;
	int apple[10];
	int pear[10];
	scanf_s("%d", &t);
	
	while (t--)
	{
		scanf("%d %d", &n, &m);
		for (i = 0; i < n; i++)
		{
			scanf("%d %d", &a, &b);
			apple[i] = a;
			pear[i] = b;
		}
		while (m--)
		{
			int max = 0;
			for (i = 0; i < n; i++)
			{

				if (apple[i] > apple[max])
				{
					max = i;
				}
				if (apple[i] == apple[max])
				{
					if (pear[i] > pear[max])
					{
						max = i;
					}
				}
			}
			printf("%d ", max + 1);
			apple[max] = -1;
			pear[max] = -1;
		}
		printf("\n");
	}
}

/*
Main.c:2:6: warning: return type of 'main' is not 'int' [-Wmain]
 void main()
      ^
Main.c: In function 'main':
Main.c:10:2: warning: implicit declaration of function 'scanf_s' [-Wimplicit-function-declaration]
  scanf_s("%d", &t);
  ^
Main.c:7:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
/tmp/ccqll06G.o: In function `main':
Main.c:(.text+0x1a): undefined reference to `scanf_s'
collect2: error: ld returned 1 exit status
*/

Double click to view unformatted code.


Back to problem 5