题解 | #扭蛋机#

扭蛋机

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

#include<bits/stdc++.h>
using namespace std;
%画出图发现N为偶数的时候,都是3,为奇数的时候都是2扭出来的,并且往前找的时候发现都是2倍关系,把每一次都当做N,从后往前寻找,然后再从后往前输出,
int main() {
    int N;
    cin >> N;
    string str;
    while(N > 0)
    {
        if(N % 2 == 1)
        {
            str += "2";
            N = N / 2; 
        }
        else
        {
            str += "3";
            N = N/2-1;    
        }
    }
   for(int i = str.length()-1; i >= 0; i--)
   {
       cout<<str[i];
   }
   cout<<endl;

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

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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