#include <iostream> #include <cmath> using namespace std; int round1(double d); int main() { double d; cin >> d; // write your code here...... // 下一句等价于 int result = round(d); int result = round1(d); cout << result << endl; return 0; } int round1(double d) { int result = int(d); // result为0时,d可能为0.0,0.3,-0.3...因此讨论 d != 0 时要考虑 result == 0 的情况 if (result >= 0 && result + 0.5 <= d) { // 下一句等价于result = ceil(d); result += 1; } else if (result <= 0 && result - 0.5 >= d) { // 下一句等价于result = floor(d); result -= 1; } return result; }