下面这个哪里可以修改
#include<bits/stdc++.h>
using namespace std;
int main()
{
double n;
int d,k;
cin>>n;
d=n;
if((n-d)<1&&(n-d)!=0) k=d+1;
if(n<=1)
{
cout<<8;
}
else if(n>1&&n<=6)
{
cout<<8+(k-1)*15;
}
else if(k>7)
{
cout<<8+75+(k-7)*20;
}
return 0;
}
判断自身乘2是不是大于转成int乘2,是说明有小数位
if(x*2>int(x)*2)
或者ceil函数向上取整
#include<bits/stdc++.h>
using namespace std;
int main()
{
double n;
cin>>n;
if(n<=1)
{
cout<<8;
}
else if(n>1&&n<=6)
{
cout<<8+(ceil(n)-1)*15;
}
else
{
cout<<8+75+ceil(n-6)*20;
}
return 0;
}
怎么不足1就按照1计算?
数据加上0.5然后取整就可以了。
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!希望对题主有所帮助!可以的话,帮忙点个采纳!