题解 | #扭蛋机#

扭蛋机

https://www.nowcoder.com/practice/9d26441a396242a9a0f7d2106fc130c7?tpId=182&tqId=34599&rp=1&ru=/exam/intelligent&qru=/exam/intelligent&sourceUrl=%2Fexam%2Fintelligent%3FquestionJobId%3D10%26tagId%3D21004&difficulty=undefined&judgeStatus=undefined&tags=&title=

using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
    public static void Main()
    {
        string line;
        int a = 0;
        string c = "";
        while ((line = System.Console.ReadLine()) != null&&line!="")
        { // 注意 while 处理多个 case
            a = Convert.ToInt32(line);
        }
       
            while (a != 1 && a != 0)
            {
                if (a % 2 == 0)
                {
                    c += "3";
                    a = (a - 2) / 2;

                }
                if (a % 2 == 1)
                {
                    c += "2";
                    a = (a - 1) / 2;
                }

            }

            if(a==1)
        {
            c += "2";
        }

       
        c = String.Join("", c.Reverse());
        Console.WriteLine(c);
    }
}

全部评论

相关推荐

头像
04-17 09:29
已编辑
湖南农业大学 后端
睡姿决定发型丫:本硕末9也是0offer,简历挂了挺多,只有淘天 美团 中兴给了面试机会,淘天二面挂,美团一面kpi面,中兴一面感觉也大概率kpi(虽然国企,但一面0技术纯聊天有点离谱吧)
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务