题解 | #取近似值#
取近似值
http://www.nowcoder.com/practice/3ab09737afb645cc82c35d56a5ce802a
#include <iostream>
using namespace std;
int main()
{
float a;
while(cin >> a)
{
int b = int(a)*10;
int c = int(a * 10);
int d = c - b;
if (d >= 5) {
std::cout << int(a)+1;
}
else {
std::cout << int(a);
}
}
}
using namespace std;
int main()
{
float a;
while(cin >> a)
{
int b = int(a)*10;
int c = int(a * 10);
int d = c - b;
if (d >= 5) {
std::cout << int(a)+1;
}
else {
std::cout << int(a);
}
}
}