为什么输出是整数而不是双精度?

Why the output is integer not double?

本文关键字:双精度 整数 输出 为什么      更新时间:2023-10-16
I just don't understand why...

  • 我的所有数据类型都是双精度型,如果其中一些不是,它们将被隐式转换为双精度。
  • 没有警告和错误。
关键是代码的
  • 输出是整数,而不是代码的其余部分。

  • 您还可以在科里鲁看到SC
  • 我知道#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

《守则》

#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);