Start: Jan, 08, 2018 19:10:00
2017年秋季学期程序设计基础(C语言)期末考试
End: Jan, 08, 2018 21:40:00
Time elapsed:
Time remaining:

Problem_ID: E
Result: Accepted
Time: 28ms
Memory: 2080kB
In contest: 1139

#include <stdio.h>
#include <string.h>
#define ARRAY 1000
struct student{
	char name[ARRAY];
	int a, b;
	int s;
}p[ARRAY], temp;
int main(void){
	int i, T, n, pass, j;
	//char ch[ARRAY];
	scanf("%d", &T);
	//getchar();
	while(T--){
		scanf("%d", &n);
		//getchar();
		for(i = 0; i < n; i++){
			getchar();
			scanf("%s %d %d", p[i].name, &p[i].a, &p[i].b);
			p[i].s = p[i].a + p[i].b;
		}
		for(pass = 1; pass < n; pass++){
			for(j = 0; j < n - pass; j++){
				if(p[j].s < p[j + 1].s){
					temp = p[j];
					p[j] = p[j + 1];
					p[j + 1] = temp;
				}
			}
		}
		for(i = 0; i < n; i++){
			printf("%s\n", p[i].name);
		}
	}
	return 0;
}