백준 Baekjoon 10698번 Ahmed Aly - JAVA

Jaeho Kim·2022년 4월 22일
0

코딩테스트

목록 보기
73/110

https://www.acmicpc.net/problem/10698

문제
Ahmed Aly was the chief judge for the last Arab Collegiate Programming Contest, and he will be the chief judge for the next one also. He was an ACM ICPC world finalist in Oralndo 2011, and currently he is a software engineer at Google.
During the last ACPC contest, it was the first time that the chief judge didn’t not attend the contest, and this was because his son Omar was expected to be born a few days before or after the contest (he was born 10 days after the contest), so he could not travel to Jordan.
Now his son Omar is old enough (9 months old) to start learning programming. His first program was very simple, just a program to add or subtract two numbers, and he needs your help to check if his program is correct or not.

입력
Your program will be tested on one or more test cases. The first line of the input will be a single integer T, the number of test cases (1 ≤ T ≤ 100). Followed by T lines, each test case is a single line containing an equation in the following format “X O Y = Z”, where X, Y and Z are positive integers (1 ≤ X,Y,Z ≤ 100) and O is either ‘+’ or ‘-’ (without the quotes).

출력
For each test case print a single line containing “Case n:” (without the quotes) where n is the test case number (starting from 1) followed by a space then “YES” (without the quotes) if the equation is correct or “NO” (without the quotes) if the equation is wrong.

예제 입력 1

4
1 + 23 = 22
1 + 22 = 23
22 - 1 = 23
23 - 1 = 22

예제 출력 1

Case 1: NO
Case 2: YES
Case 3: NO
Case 4: YES
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.nextLine());

		for (int i = 0; i < N; i++) {
			String[] str = sc.nextLine().split(" ");

			int sum = 0;

			int a = Integer.parseInt(str[0]);
			int b = Integer.parseInt(str[2]);
			int c = Integer.parseInt(str[4]);

			if (str[1].equals("+")) {
				sum = a + b;
			} else if (str[1].equals("-")) {
				sum = a - b;
			}

			System.out.println("Case " + (i + 1) + ": " + (sum == c ? "YES" : "NO"));
		}
		sc.close();
	}
}
  • 설명
  • 영어를 번역기 돌리고 풀었는데.... 리턴값을 예, 아니오로 해서 1회 오류가 났다..ㅎㅎ
profile
Hello, World!

0개의 댓글