I just don't understand why...
- 关键是代码的输出是整数,而不是其余代码。
#include<bits/stdc++.h>
不是标准库中的头文件,只是GCC的内部实现,但这不是重点。请帮助我。
您可以输入以下示例
6 6 7
01234 880
a1903 199
ydjh2 200
wehu8 300
dx86w 220
missing 400
ydhfu77 99
wehu8 55
ydjh2 98
dx86w 88
a1903 86
01234 39
ydhfu77 88
a1903 66
01234 58
wehu8 84
ydjh2 82
missing 99
dx86w 81
The代码
#include<bits/stdc++.h>
using namespace std;
typedef pair<string, array<double, 5>> PAIR;
bool cmp(PAIR x, PAIR y) {
if (round(x.second[3]) != round(y.second[3])) return x.second[3] > y.second[3];
else return x.first < y.first;
}
int main() {
map<string, array<double, 5>> student;
int p, m, n, online, score;
string name;
cin >> p >> m >> n;
while (p--) {
cin >> name >> online;
student[name][0] = online;
}
while (m--) {
cin >> name >> score;
if (score) student[name][1] = score;
else student[name][4] = 1;
}
while (n--) {
cin >> name >> score;
student[name][2] = score;
int mid = student[name][1];
if (mid > score) student[name][3] = mid * 0.4 + score * 0.6;
else student[name][3] = score;
}
for (auto p = student.begin(); p != student.end(); ) {
if (p->second[0] < 200 || round(p->second[3]) < 60 || p->second[0] > 900) student.erase(p++);
else p++;
}
vector<PAIR> answer(student.begin(), student.end());
sort(answer.begin(), answer.end(), cmp);
for (auto v : answer) {
if (!v.second[1] && !v.second[4]) cout << v.first << " " << v.second[0] << " " << -1 << " " << v.second[2] << " " << round(v.second[3]) << endl;
else cout << v.first << " " << v.second[0] << " " << v.second[1] << " " << v.second[2] << " " << round(v.second[3]) << endl;
}
return 0;
}
您仅看到完整的值,因为默认情况下,double
的打印精度有限(例如6位数字),而尾随的零将被忽略。
也使用四舍五入的值:
round(v.second[3])
尝试添加
#include <iomanip>
std::cout << std::fixed << std::setprecision(2);