umilove98의 블로그

백준 1864 Java 자바 본문

algorithm/백준

백준 1864 Java 자바

umilove98 2021. 8. 10. 13:04
반응형

 

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
58
59
60
61
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
 
public class Q1864 {
 
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        while(true) {
            String s = br.readLine();
            ArrayList<Character> charlist = new ArrayList<Character>();
            
            for(int i = s.length()-1; i >= 0 ; i--) {    // 입력받은 문자열을 가장 낮은 자리부터 처리하기 위해 뒤에서부터 차례대로 리스트에 넣어준다 
                if(s.charAt(i) == '#') {
                    return;
                }
                charlist.add(s.charAt(i));
            }
            
            int result = 0;
            for(int i = 0; i < charlist.size(); i++) {
 
                switch(charlist.get(i)) {
                case '-':
                    result += 0;
                    break;
                case '(':
                    result += 2 * Math.pow(8, i);
                    break;
                case '@':
                    result += 3 * Math.pow(8, i);
                    break;
                case '?':
                    result += 4 * Math.pow(8, i);
                    break;
                case '>':
                    result += 5 * Math.pow(8, i);
                    break;
                case '&':
                    result += 6 * Math.pow(8, i);
                    break;
                case '%':
                    result += 7 * Math.pow(8, i);
                    break;
                case '/':
                    result += -1 * Math.pow(8, i);
                    break;
                default:    // '\' 는 case에 지정이 안돼서 default값일 때를 1로 두고 처리함
                    result += Math.pow(8, i);
                    break;
                }
            }
            System.out.println(result);
        }
 
    }
 
}
 
cs
반응형

'algorithm > 백준' 카테고리의 다른 글

백준 1475 Java 자바  (0) 2021.08.11
백준 1439 Java 자바  (0) 2021.08.10
백준 1436 Java 자바  (0) 2021.08.09
백준 1837 Java 자바  (0) 2021.08.09
백준 1427 Java 자바  (0) 2021.08.07