forDevLife
[부스트캠프] 자가진단 문제 본문
- 배열 입력 받는 과정에서, 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);
}
}
'알고리즘' 카테고리의 다른 글
[백준] 2720 - 세탁소 사장 동혁 (0) | 2021.06.09 |
---|---|
[백준] 10162 - 전자레인지 (0) | 2021.06.08 |
[이코테]만들 수 없는 금액 <그리디> (0) | 2021.05.03 |
[이코테]곱하기 혹은 더하기 <그리디> (0) | 2021.05.03 |
[이코테]모험가 길드 <그리디> (0) | 2021.05.03 |
Comments