Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
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
Tags
more
Archives
Today
Total
관리 메뉴

forDevLife

[부스트캠프] 자가진단 문제 본문

알고리즘

[부스트캠프] 자가진단 문제

JH_Lucid 2021. 5. 24. 14:10

 

- 배열 입력 받는 과정에서, StringTokenizer를 사용하다가 조금 헤맸다.

- 걍 token이 더 있을 때만 arr[i], check에 값을 넣는 방식으로 했다

- 개행문자("\\n")으로 토큰이 들어올 때, break 하는 방법은 잘 안되는 것 같다.

 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine(), " ");

        int[] arr = new int[100];
        int[] check = new int[101];

        String tmp = " ";
        for(int i=0; i<100; i++) {
            if(st.hasMoreTokens()) {
                tmp = st.nextToken();
                arr[i] = Integer.parseInt(tmp);
                check[Integer.parseInt(tmp)]++;
            }
        }
        String tp = "-1";
        tmp = "";
        for(int i=1; i<101; i++) {
            if(check[i] > 1) {
                tmp += check[i] + " ";
            }
        }
        if(tmp == "") {
            System.out.println(tp);
        } else
            System.out.println(tmp);

    }
}


Comments