题解 | #学生基本信息输入输出#
学生基本信息输入输出
https://www.nowcoder.com/practice/58b6a69b4bf943b49d2cd3c15770b9fd
#include <iostream> #include <iomanip> #include <math.h> using namespace std; //计算平方 //小数点保留bits位,并对后一位进行四舍五入 double Round(double number, int bits) // 1.1 1.11 1.111 { //求个位数字进行判断 double oldNumber = number; //1.1 for(int i = 0; i <= bits; i++) { oldNumber *= 10; } int newNumber = oldNumber; //1100 int x = newNumber % 10; //1 double ret = 0.0; if(x >= 5 ) { return ret = (newNumber + 5) / pow(10, bits+1); }else { return number; } } int main() { unsigned long id; float xa , xb , xc ; char c; //读掉字符 cin >> id >> c >> xa >> c >> xb >> c >> xc; //cout.precision(2); cout << fixed; cout << setprecision(2); cout << "The each subject score of No. " << id << " is " << Round(xa, 2) << ", " << Round(xb, 2) << ", "<< Round(xc, 2) << "." << endl; return 0; } // 64 位输出请用 printf("%lld")