题解 | #魔法数字变换#

魔法数字变换

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);
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务