题解 | 实现四舍五入
#include <iostream>
using namespace std;
int main() {
double input;
cin >> input;
if (input >= 0) {
int temp = int(input * 10) % 10;
if (temp >= 5) {
cout << int(input) + 1 << endl;
} else {
cout << int(input) << endl;
}
} else {
// 负数取余还是负数
int temp = -(int(input * 10) % 10);
if (temp >= 5) {
cout << int(input) - 1 << endl;
} else {
cout << int(input) << endl;
}
}
}
// 64 位输出请用 printf("%lld")
查看17道真题和解析

