'Xhaeneung'에 해당되는 글 1건

  1. 2021.12.29[XHAENEUNG] 째능 교육

Java 로 풀어보는 알고리즘입니다. 📖
코딩테스트를 대비하여 JAVA1.8 부터 제공되는 함수형 API 는 사용하지 않았습니다.

문제 : https://www.algospot.com/judge/problem/read/XHAENEUNG

 

algospot.com :: XHAENEUNG

째능 교육 문제 정보 문제 산업 기능 요원 복무를 무사히 마치고 학교로 돌아온 xhae는 최근 복학을 위한 많은 지출로 인해 자금난에 허덕이고 있었다. 이러한 xhae가 선택한 일은 다름 아닌 째능

www.algospot.com

 

풀이입니다. 🤔

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.util.*;
 
public class Main {
    private static final String[] matches = new String[]{
            "zero""one""two""three""four""five""six""seven""eight""nine""ten"
    };
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
 
        int cases = scanner.nextInt();
        while (cases-- > 0) {
            int a = parseNumber(scanner.next());
            String op = scanner.next();
            int b = parseNumber(scanner.next());
            scanner.next();
            String c = scanner.next();
 
            int expected;
            switch (op) {
                case "+":
                    expected = a + b;
                    break;
 
                case "-":
                    expected = a - b;
                    break;
 
                case "*":
                    expected = a * b;
                    break;
 
                default:
                    throw new IllegalArgumentException();
            }
 
            boolean ret = false;
            if (expected >= 0 && expected < matches.length) {
                char[] expectedArray = matches[expected].toCharArray();
                char[] actualArray = c.toCharArray();
                Arrays.sort(expectedArray);
                Arrays.sort(actualArray);
                ret = Arrays.equals(expectedArray, actualArray);
            }
 
            System.out.println(ret ? "Yes" : "No");
        }
    }
 
    private static int parseNumber(String str) {
        for (int i = 0, len = matches.length; i < len; ++i) {
            if (matches[i].equals(str)) return i;
        }
 
        throw new IllegalArgumentException();
    }
}
cs

 


이 포스트를 읽어주셔서 감사합니다. 🙇🏻‍♂️

반응형

'개발이야기 > 알고스팟' 카테고리의 다른 글

[HAMMINGCODE] Hamming Code  (0) 2021.12.30
[WEIRD] Weird Numbers  (0) 2021.12.30
[URI] URI Decoding  (0) 2021.12.29
[BOARDCOVER] 게임판 덮기  (0) 2021.12.28
[HOTSUMMER] 에어컨을 끈다고 전력난이 해결될까?  (0) 2021.12.27
Posted by N'