为什么输出是整数而不是双精度?
Why the output is integer not double?
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);
相关文章:
- 我可以信任表示整数的浮点或双精度来保持精度吗
- C 字符串返回字符串的整数/双精度/长整型值
- 如何防止双精度值到整数的隐式转换
- 野牛/flex:计算器将双精度值解释为整数,所以我添加了 YYSTYPE 双精度 #define 但我有多个编译错误
- 为什么输出是整数而不是双精度?
- 从字符串转换为双精度和整数 - C++
- 从双精度转换为整数的显式类型是否始终检查整数溢出?
- C++,遇到将双精度转换为整数的问题
- 用双精度除以整数
- 使用整数初始化列表初始化长双精度的向量
- 如何判断 c++ 向量中的值类型(整数或双精度)?
- 了解双精度转换与整数转换中的整数与截断关系
- 为什么使用 int64_t 会产生错误的结果,而双精度则按预期进行简单的整数乘法
- 将双精度与整数进行比较
- 64 位整数到双精度冲突
- 在编译时将整数和分数部分宏组合成一个新的宏或双精度
- 不确定输出双精度或整数的代码行
- 双精度/整数模板函数的向量
- 如何通过 JNI 设置 java 类的双精度/整数类型的值
- 将输入验证为双精度/整数的函数