题解 | #扭蛋机#

扭蛋机

https://www.nowcoder.com/practice/9d26441a396242a9a0f7d2106fc130c7

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
void Calculate(int inx, string& outchars) {
    if (inx == 0)return;
    if (inx % 2 == 0) {
        int x = inx / 2 - 1;
        outchars.push_back('3');
        Calculate(x, outchars);
    } else {
        int x = inx / 2;
        outchars.push_back('2');
        Calculate(x, outchars);
    }
}
void BL1() {
    int n;
    while (cin >> n) {
        string tempresult;
        Calculate(n, tempresult);
        reverse(tempresult.begin(), tempresult.end());
        cout << tempresult << endl;
    }
}
int main() {
    BL1();
}

全部评论

相关推荐

见见123:简历没有啥问题,是这个社会有问题。因为你刚毕业,没有工作经历,现在企业都不要没有工作经历的。社会病了。
点赞 评论 收藏
分享
05-14 20:34
门头沟学院 Java
窝补药贝八股:管他们,乱说,反正又不去,直接说680
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务