题解 | #取近似值#
取近似值
https://www.nowcoder.com/practice/3ab09737afb645cc82c35d56a5ce802a
输入的其实时字符串,对分界点 point(.) 右边的数字进行判断,然后返回point左边的数字字符串
#include <iostream> #include <string> #include <cmath> using namespace std; void similarNum(string num) { for (int i = 0; i < num.length(); i++) { if (!isalnum(num[i])) { // 为其他字符时 if (num[i + 1] - '5'>= 0) { cout << stoi(num.substr(0,i)) + 1 << endl;; } else { cout << stoi(num.substr(0, i)) << endl; } } } } int main() { string num; getline(cin, num); similarNum(num); return 0; }
#社招#