题解 | #汽水瓶#
汽水瓶
https://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f
#include <iostream> using namespace std; int getExtraBottles(int n){ if(n==0 || n==1 || n==2) return 0; int res = 0; int three = 0; while(n>=3){ n -= 3; res++; three++; n++; // 下面代码多余了,上面n++意味着已经是积累到3瓶就换一瓶了 // if(three==3){ // n++; // res++; // three = 0; // } } if(n==2){ res++; } return res; } int main() { int m,n,res; while(cin>>n){ if(n==0) return 0; res = getExtraBottles(n); cout<<res<<endl; } } // 64 位输出请用 printf("%lld")