View Code of Problem 83

#include <stdio.h>
typedef struct{
	int num;
	int score;
}student;
int main(){
	int N,M,i,j,max;
	scanf("%d %d",&N,&M);
	student a[N+M],swap;
	for(i=0;i<N+M;i++){
		scanf("%d %d",&a[i].num,&a[i].score);
	}
	for(i=1;i<=N+M-1;i++){
		max=0;
		for(j=0;j<N+M-i+1;j++){
			if(a[j].num>a[max].num) max=j;
		}
		swap=a[max];
		a[max]=a[N+M-i];
		a[N+M-i]=swap;
	}
	for(i=0;i<N+M;i++){
		printf("%d %d\n",a[i].num,a[i].score);
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 83