题解 | #汽水瓶#

汽水瓶

https://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f

#include <iostream>
using namespace std;

int main() {
    int n;
    int num[10] = {0};
    int j = 0;
    while (cin >> n) {
        if (n != 0) {
            int temp = 0;
            int temp1 = 0;
            int temp2 = 0;
            temp = n / 3;
            temp1 = n % 3;

            num[j] += temp;

            while (1) {

                temp2 = temp1 + temp;
                if ((temp2) < 3) {
                    num[j] += temp2 - 1;
                    break;
                } else {
                    temp1 = (temp2) % 3;
                    temp = (temp2) / 3;
                    num[j] += temp;

                }
            }
            j++;
        } else if (n == 0) {
            for (int i = 0; i < j; i++) {
                cout << num[i] << endl;
            }
        }

    }


}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

learYuan:🐕看了都摇头
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务