9.11网易雷火web后端笔试

投票
第二题给你一个坐标x,y。问从0,0像素点的左下角到x,y像素点的右上角经过多少个像素点。
大家做了几道题

```java
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int x = in.nextInt();
        int y = in.nextInt();
        // RuntimeException runtimeException = new RuntimeException(x+" "+y);
        // throw runtimeException;
        if (x == y) {
            System.out.println(x + 1);
            return;
        }
        if (y > x) {
            int temp = x;
            x = y;
            y = temp;
        }
        int gcd = get(x + 1, y + 1);
        if (gcd == 1) {
            System.out.println(x + y + 1);
        } else {
            int temp = (x + 1) / gcd - 1 + (y + 1) / gcd - 1 + 1;
            System.out.println(temp * gcd);
        }
    }

    static int get(int x, int y) {
        if (y == 0) {
            return x;
        }
        return get(y, x % y);
    }
}
```
全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 11:16
点赞 评论 收藏
分享
能干的三文鱼刷了10...:公司可能有弄嵌入式需要会画pcb的需求,而且pcb能快速直观看出一个人某方面的实力。看看是否有面试资格。问你问题也能ai出来,pcb这东西能作假概率不高
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 11:22
怎么这么多逆天求职者,救救我救救我救救我😭
flmz_Kk:哈哈哈哈哈哈,这么多求职者,肯定有那一两个逆天的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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