题解 | #魔法数字变换#

魔法数字变换

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

public class Program {
    public static void Main() {
        int inPut = int.Parse(System.Console.ReadLine());

        int index = 0;
        while (inPut != 1) {
            if (inPut % 2 == 0)
                inPut /= 2;
            else if (inPut % 2 != 0)
                inPut = (inPut * 3) + 1;
            index++;
        }
        System.Console.WriteLine(index);
    }
}

全部评论

相关推荐

太难了,双9bg也被刷
投递韶音科技等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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