要求:
http://codeup.cn/problem.php?cid=100000584&pid=1
说明:
学习这种使用while的套路!!
代码:
#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
int n;
double count = 0;
while(scanf("%d",&n),n != 0){
if(n <= 4){
count = 10;
//printf("10\n");
}
else if(n >4 && n <=8 ){
count = 10 +(n-4)*2;
//printf("%d\n",10 +(n-3)*2);
}
else if(n >8){
//用好while是关键
while(n >=8){
count = count + 18;
n = n - 8;
}
if(n <= 4){
count = count + 2.4*n;
}
else{
count = count + 10 + (n - 4)*2;
}
}
if(count == (int)count){
printf("%d\n",(int)count);
}
else{
printf("%.1f\n",count);
}
//重新让count为0,否则重复算会出错
count = 0;
}
}