PAT乙级1004. 成绩排名(C语言)

AC

PAT乙级真题答案目录


#include 

typedef struct {
	char name[11];
	char id[11];
	int scores;
} student;

int main() {
	int n, max = -1, min = 101, maxId, minId;
	scanf("%d", &n);
	student s[n];
	for(int i = 0; i < n; i++) {
		scanf("%s %s %d", s[i].name, s[i].id, &s[i].scores);
		if(s[i].scores > max) {
			max = s[i].scores;
			maxId = i;
		}
		if(s[i].scores < min) {
			min = s[i].scores;
			minId = i;
		}
	}
	printf("%s %s\n", s[maxId].name, s[maxId].id);
	printf("%s %s\n", s[minId].name, s[minId].id);
	return 0;
}

你可能感兴趣的:(PAT乙级真题)