解题思路:先写出空瓶子数的函数,再将每一个数据对应的答案存储在数组中,最终输出
注意事项:
参考代码:#include <stdio.h>
#include <stdlib.h>
#define N 10
int emptybottle(int n);/计算空瓶子数的函数
int main()
{
int n;
int i = 0;
int answer[N] = {0};
scanf("%d", &n);
while(n != 0)
{
answer[i] = emptybottle(n);
i++;
scanf("%d", &n);
}
for (int j = 0;j< i;j++)//输出答案
{
printf("%d\n",answer[j]);
}
return 0;
}
int emptybottle(int n)
{
int sum = 0;
while(n != 1 && n!=0)
{
if(n == 2)
n +=1;
sum += n/3;
n = n/3 + n%3;
}
return sum;
}
0.0分
0 人评分