Сегодня мой 39-й день кодинга. Я решил одну проблему.
Проблема: кошки и мыши
Образец ввода 0
2 1 2 3 1 3 2
Пример вывода 0
Cat B Mouse C
Решение (в Java):
import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; public class Solution { static String catAndMouse(int x, int y, int z) { int a=z-x; int b=z-y; int cata=Math.abs(a); int catb=Math.abs(b); if( cata<catb) return "Cat A"; else if(catb<cata) return "Cat B"; else return "Mouse C"; } private static final Scanner scanner = new Scanner(System.in); public static void main(String[] args) throws IOException { BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); int q = scanner.nextInt(); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); for (int qItr = 0; qItr < q; qItr++) { String[] xyz = scanner.nextLine().split(" "); int x = Integer.parseInt(xyz[0]); int y = Integer.parseInt(xyz[1]); int z = Integer.parseInt(xyz[2]); String result = catAndMouse(x, y, z); bufferedWriter.write(result); bufferedWriter.newLine(); } bufferedWriter.close(); scanner.close(); } }