万能的map
2025-09-21 22:07:05
发布于:上海
2阅读
0回复
0点赞
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
struct Student {
int id;
double score;
};
int main() {
int n;
cin >> n;
string key;
cin >> key;
vector<Student> students(n);
for (int i = 0; i < n; i++) {
string answer;
cin >> answer;
students[i] = {i + 1, 0.0};
int pos = 0;
for (int j = 0; j < 15; j++) {
if (answer[pos] == key[pos]) {
students[i].score += 2.0;
}
pos++;
}
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
if (answer[pos] == key[pos]) {
students[i].score += 1.5;
}
pos++;
}
for (int k = 0; k < 2; k++) {
if (answer[pos] == key[pos]) {
students[i].score += 2.0;
}
pos++;
}
}
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 5; k++) {
if (answer[pos] == key[pos]) {
students[i].score += 2.0;
}
pos++;
}
}
}
sort(students.begin(), students.end(), [](const Student& a, const Student& b) {
if (a.score != b.score) return a.score > b.score;
return a.id < b.id;
});
for(const auto&s : students) {
cout << s.id << " ";
long long co = s.score;
if(co == s.score) cout << co << endl;
else printf("%.1lf\n",s.score);
}
return 0;
}
这里空空如也
有帮助,赞一个