[Lucky Algorithm] Cats and a Mouse(24/77)
Cats and a Mouse (Hacker Rank)
Two cats named and are standing at integral points on the x-axis. Cat is standing at point and cat is standing at point . Both cats run at the same speed, and they want to catch a mouse named that’s hiding at integral point on the x-axis. Can you determine who will catch the mouse?
You are given queries in the form of , , and . For each query, print the appropriate answer on a new line:
If cat catches the mouse first, print Cat A. If cat catches the mouse first, print Cat B. If both cats reach the mouse at the same time, print Mouse C as the two cats fight and mouse escapes.
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int q = in.nextInt();
for(int a0 = 0; a0 < q; a0++){
int x = in.nextInt();
int y = in.nextInt();
int z = in.nextInt();
if(Math.abs(z-x) > Math.abs(z-y)){
System.out.println("Cat B");
}else if(Math.abs(z-x) < Math.abs(z-y)){
System.out.println("Cat A");
}else{
System.out.println("Mouse C");
}
}
}
}
행운의 77문제 프로젝트
행운의 77문제 프로젝트는 한 달동안 알고리즘 문제 77개를 푸는 프로젝트입니다.