不知道sort为啥会报错qnq
查看原帖
不知道sort为啥会报错qnq
643402
cyz_luogu楼主2021/12/17 10:22
#include<stdio.h>
#include <algorithm>
using namespace std;
#include<iostream>
using namespace std;
bool cmp(students x, students y) {
	if (x.score == y.score)return x.id < y.id;
	return x.score > y.score;
}
struct students {
	string name;
	int Chinese, Maths, English, score,id;
};
students a[1001];
int main() {
	int n,maxx=0,w;
	cin >> n;
	for (int i=0; i < n; i++) {
		cin >> a[i].name >> a[i].Chinese >> a[i].Maths >> a[i].English ;
		a[i].score = a[i].Chinese + a[i].Maths + a[i].English;
		a[i].id = i;
	}
	sort(a,a + n, cmp);

	for (int j = 0; j < n; j++) {
		if (maxx < a[j].score) {
			maxx = a[j].score;
			w = j;
		}
	}
		cout << a[w].name << " " << a[w].Chinese << " " << a[w].Maths << " " << a[w].English;
	return 0;
}```
是这样的代码但是sort那里会标红不知道哪里错了pnp有大佬能指点一下迷津吗
2021/12/17 10:22
加载中...