• 문제 링크
3022번: PRASE
The first line of input contains an integer N (1 ≤ N ≤ 100), how many pieces of food the children take. Each of the following N lines contains the name of a child that took one piece of food. The names will be strings of at most 20 lowercase letters
www.acmicpc.net
• 풀이 과정
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
Map<String, Integer> map = new HashMap<>();
int cnt = 0;
for (int i = 0; i < n; i++) {
String key = br.readLine();
int value = map.getOrDefault(key, 0);
if (value > i - value)
cnt++;
map.put(key, value + 1);
}
bw.write(String.valueOf(cnt));
bw.flush();
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 22864 피로도 - Greedy / Java (0) | 2023.05.06 |
---|---|
[백준] 25644 최대 상승 - Greedy / Java (0) | 2023.05.05 |
[백준] 9612 Maximum Word Frequency - Data Structure / Java (0) | 2023.05.03 |
[백준] 24511 queuestack - Data Structure / Java (0) | 2023.05.02 |
[백준] 9872 Record Keeping - Data Structure / Java (0) | 2023.05.01 |
댓글