每日一练4:牛牛的快递(含链接)
链接:
牛牛的快递_牛客题霸_牛客网
题目:
代码1:
#include <iostream>
using namespace std;
int main() {
double mo;
char ch;
int ret = 0;
cin >> mo >> ch;
if(ch == 'y') ret += 5;
ret += 20;
if(mo <= 1)
{
cout << ret;
return 0;
}
else
{
double tmp = mo -1;
if( (tmp - (int)tmp) > 0) ret += (int)tmp + 1 ;
else ret += (int)tmp;
}
cout << ret;
return 0;
}
代码2:
#include <cmath>
#include <iostream>
using namespace std;
int main() {
double mo;
char ch;
int ret = 0;
cin >> mo >> ch;
if(ch == 'y') ret += 5;
ret += 20;
if(mo > 1) ret += ceil(mo - 1);
cout << ret;
return 0;
}
思路:
向上取整
或者使用ceil()函数, 也可以达到向上取整的效果