竞赛
考级
#include<iostream> #include <cmath> using namespace std; int main(){ string d; double n; cin>>d >> n; if(d=="ceil"){ cout << ceil(n); }else if(d=="floor"){ cout << floor(n); }else{ cout << round(n); } return 0; }
AGGO互关
zaze
数学函数 题目解析 本道题目考查三个函数的使用。 C++下直接使用函数就行了 特别注意如果是Python下的round()需要特殊的处理一下。 在 Python 中,round() 函数用于将数字四舍五入到给定的精度。它的语法为: * number: 必需参数,表示要四舍五入的数字。 * ndigits: 可选参数,指定要保留的小数位数。如果省略此参数,则默认对整数进行四舍五入。 具体行为 1. 四舍六入五成双: 当对浮点数进行四舍五入时,round() 函数采用"银行家舍入法"(也称为"四舍六入五成双"),即对于位于两边相等的数字(如 2.5),它会将该数字舍入到最接近的偶数。 * round(2.5) 返回 2,而 round(3.5) 返回 4。 2. 保留指定小数位数: 如果 ndigits 参数给定,round() 将四舍五入到指定的小数位数。 * round(3.14159, 2) 返回 3.14。 3. 整数的舍入: 如果没有提供 ndigits,round() 会将浮点数四舍五入为整数。 * round(3.75) 返回 4。 示例 对于更精确的控制,例如你在代码中使用的 Decimal 对象,可以指定具体的舍入模式,如 ROUND_HALF_UP。 AC代码
AC君
#include <iostream> #include <cmath> #include <algorithm> using namespace std; int main() { string a; double n; cin>>a>>n; if(a=="ceil"){ cout<<ceil(n); }else if(a=="floor"){ cout<<floor(n); }else{ cout<<round(n); } return 0; }
༺ཌༀ`§☯末影之路☯§′ༀད༻
zsy
熙熙熙熙
回来看看
无敌的鳖佬仔给老爷爷猜猜被
#include <bits/stdc++.h> using namespace std; int main() { string s; double n; cin >> s >> n; if(s == "ceil") { printf("%.0lf",ceil(n)); } if(s == "floor") { printf("%.0lf",floor(n)); } if(s == "round") { printf("%.0lf",round(n)); } return 0; }
凤凰-碍持达芬得入
~~***
陈亦然
提交答案之后,这里将显示提交结果~