题解 | #汽水瓶#
汽水瓶
https://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f
#include <iostream> using namespace std; int main() { int n; while (cin >> n) { if (n == 0) //满足 n=0 表示输入结束 break; int count = 0; while (n > 1) { if (n == 2) //还剩2瓶时可以借一瓶 { count++; n = 0; } else { count += n / 3; //能换的汽水取决于整除的结果 n = n % 3 + n / 3; //喝完后的空瓶数是余数加整除结果之和 } } cout << count << endl; } return 0; }