티스토리 뷰

문제

다솜이는 은진이의 옆집에 새로 이사왔다. 다솜이는 자기 방 번호를 예쁜 플라스틱 숫자로 문에 붙이려고 한다.

다솜이의 옆집에서는 플라스틱 숫자를 한 세트로 판다. 한 세트에는 0번부터 9번까지 숫자가 하나씩 들어있다. 다솜이의 방 번호가 주어졌을 때, 필요한 세트의 개수의 최소값을 출력하시오. (6은 9를 뒤집어서 이용할 수 있고, 9는 6을 뒤집어서 이용할 수 있다.)

입력

첫째 줄에 다솜이의 방 번호 N이 주어진다. N은 1,000,000보다 작거나 같은 자연수이다.

출력

첫째 줄에 필요한 세트의 개수를 출력한다.

예제 입력 

9999

예제 출력 

2


코드


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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package string;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
 
/**
 * https://www.acmicpc.net/problem/1475
 * 방 번호
 * @author minjung
 *
 */
public class baekjoon_1475 {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        sc.init();
        
        String num = sc.readLine();
        new baekjoon_1475().solve(num);
    }
    
    private void solve(String num) {
        int[] number = new int[10];
        
        for ( int i = 0; i < num.length(); i++ ){
            number[num.charAt(i)-48]++;
        }
        
        int max = 0;
        int index = 0;
        int result  = 0;
        
        for ( int i = 0; i < number.length; i ++ ){
            if ( max < number[i] ){
                max = number[i];
                index = i;
            }
        }
        
        if ( index == 9 || index == 6 ){
            result = (int) Math.round((double)(number[9+ number[6]) / 2);
            System.out.println(result);
        }
        else {
            System.out.println(max);
        }
    }
 
    static class sc { 
        private static BufferedReader br;
        private static StringTokenizer st;
        
        static void init() {
            br = new BufferedReader(new InputStreamReader(System.in));
            st = new StringTokenizer("");
        }
        
        static String readLine() {
            try{
                return br.readLine();
            } catch (IOException e){
                e.printStackTrace();
            }
            return null;
        }
        
        static String next() {
            while (!st.hasMoreTokens() ){
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        static long nextLong() {
            return Long.parseLong(next());
        }
        
        static int nextInt() {
            return Integer.parseInt(next());
        }
        
        static double nextDouble() {
            return Double.parseDouble(next());
        }
        
    }
 
}
 
cs


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
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
글 보관함