#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
//用结构体存储学生信息
struct stuInfo {
public:
string stuName;
// ID 用来应对同分情况
int cnScore, mathScore, engScore, totScore, ID;
} stu[1005];
//应对同分情况
bool cmp(const stuInfo &a, const stuInfo &b) {
return a.totScore == b.totScore ? a.ID < b.ID : a.totScore < b.totScore;
}
bool isCompStudent(const stuInfo &stuA, const stuInfo &stuB) {
int totScrGap, cnScrGap, matScrGap, engScrGap;
totScrGap = abs(stuB.totScore - stuA.totScore);
cnScrGap = abs(stuB.cnScore - stuA.cnScore);
matScrGap = abs(stuB.mathScore - stuA.mathScore);
engScrGap = abs(stuB.engScore - stuA.engScore);
return totScrGap <= 5 && cnScrGap <= 10 && matScrGap <= 10 && engScrGap <= 10;
}
int main(int argc, char const *argv[]) {
int stuNumber;
cin >> stuNumber;
for (int i = 0; i < stuNumber; ++i) {
cin >> stu[i].stuName >> stu[i].cnScore >> stu[i].mathScore >> stu[i].engScore;
stu[i].totScore = stu[i].cnScore + stu[i].mathScore + stu[i].engScore;
stu[i].ID = i;
}
sort(stu, stu + stuNumber, cmp);
for (int i = 0; i < stuNumber; ++i) {
if (isCompStudent(stu[i], stu[i + 1])) {
cout << stu[i].stuName << ' ' << stu[i + 1].stuName << endl;
}
}
return 0;
}
这个怎么错了啊 纯萌新。。