题解 | #汽水瓶#
汽水瓶
https://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f
#include <iostream>
using namespace std;
int main() {
int a;
while (cin >> a && a != 0) { // 注意 while 处理多个 case
int num = 0;
//一瓶喝不到的话,直接输出
if (a <= 1) {
cout << num << endl;
continue;
}
//将能直接换的情况弄完
while (a >= 3) {
a = a - 3 + 1; //加一的原因是,三瓶兑换后,就又有一瓶新的了
num++;
}
//向老板借的情况
if (a == 2){
num++;
}
cout << num << endl;
}
return 0;
}
// 64 位输出请用 printf("%lld")
查看22道真题和解析
美的集团公司福利 727人发布