View Code of Problem 5

#include<stdio.h>
struct fruit{
	int pear;
	int peach;
}; 
int main()
{
	int t,n,m,i,j=0;
	scanf("%d",&t);
	while()
	{
		int s=0;
		scanf("%d %d",&n,&m);
		struct fruit a[n];
		for(i=0;i<n;i++)
		{
			scanf("%d %d",&a[i].pear,&a[i].peach);
		}
		while(m--)
		{
			int x=0,k;
			for(k=i=0;i<n-1;i++)//i<2
		    {
                if(a[k].pear<a[i+1].pear)
                	k=i+1;
				else if(a[k].pear>a[i+1].pear)
					k=k;
				else if(a[k].pear==a[i+1].pear)
				{
					if(a[k].peach<a[i+1].peach)
					    k=i+1;
					else if(a[k].peach>a[i+1].peach)
					    k=k;
					else
					    k=k;
				}
		    }
			a[k].pear=0;a[k].peach=0;
			s++;
		    printf("%d",k+1); 
		    if(s<n)
		        printf(" "); 
		}	
		printf("\n");
	}
	return 0;
}
/*
Main.c: In function 'main':
Main.c:10:8: error: expected expression before ')' token
  while()
        ^
Main.c:39:4: error: 's' undeclared (first use in this function)
    s++;
    ^
Main.c:39:4: note: each undeclared identifier is reported only once for each function it appears in
Main.c:21:8: warning: unused variable 'x' [-Wunused-variable]
    int x=0,k;
        ^
Main.c:8:14: warning: unused variable 'j' [-Wunused-variable]
  int t,n,m,i,j=0;
              ^
*/

Double click to view unformatted code.


Back to problem 5