题解 | 变幻莫测 c#

变幻莫测

https://www.nowcoder.com/practice/5e702b6c7c114e64b5db4650d0ce0051

using System;
using System.Collections.Generic;
public class Program {
    public static void Main() {
        string[] inputs = Console.ReadLine().Split(' ');
        int.TryParse(inputs[0], out int x);
        int.TryParse(inputs[1], out int y);

        HashSet<int> historyOfChange = new HashSet<int>();

        int changeCount = 0;
        //依旧是在纸上穷举,总共有4种情况是可以得到最少操作数的:Y 为 0 的情况,X 为 0 的情况,X 和 Y 相等的情况,X 与 Y 互为相反数的情况
        if (x == y)
            Console.WriteLine(0);
        else if (y == 0)
            Console.WriteLine(1);
        else if (x == 0)
            Console.WriteLine(2);
        else if (x == -y)
            Console.WriteLine(3);
        else
            Console.WriteLine(-1);
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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