HJ22 题解 | #汽水瓶#
汽水瓶
https://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f
#include <iostream>
using namespace std;
int main() {
int empty=0, full=0, ans=0; //空瓶子数,汽水数,汽水数总和
while(true){
cin>>empty;
if(empty==0){ //空瓶子为0直接结束程序
break;
}
full=0;
ans=0;
while(empty>2){
full=empty/3;
empty=empty%3 + full; //更新空瓶子数量
ans+=full;
}
if(empty==2){ //空瓶子为2则特殊处理
ans+=1;
}
cout<<ans<<endl;
}
return 0;
}
// 64 位输出请用 printf("%lld")
华为机试刷题实录 文章被收录于专栏
记录一下本科应届生(我自己)刷华为机试题的过程
查看10道真题和解析
