• 문제 링크
https://www.acmicpc.net/problem/15595
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;
public class Main {
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
Map<String, Integer> map = new HashMap<>();
int n = read(), cnt = 0, sum = 0;
while (n-- > 0) {
read();
String s = readStr();
int i = read();
skip();
if (map.getOrDefault(s, 0) == -1 || s.equals("megalusion")) continue;
if (i == 4) {
cnt++;
sum += map.getOrDefault(s, 0);
map.put(s, -1);
} else map.put(s, map.getOrDefault(s, 0) + 1);
}
bw.write(String.valueOf(cnt == 0 ? 0 : (double) cnt / (cnt + sum) * 100.0));
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
private static String readStr() throws IOException {
sb.setLength(0);
int c;
while ((c = System.in.read()) > 47) sb.append((char) c);
return sb.toString();
}
private static void skip() throws IOException {
int c;
while ((c = System.in.read()) != '\n') if (c == -1) break;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 1270 전쟁 - 땅따먹기 - Data Structure / Java (0) | 2025.05.01 |
---|---|
[백준] 1764 듣보잡 - Data Structure / Java (0) | 2025.04.30 |
[백준] 11531 ACM 대회 채점 - Data Structure / Java (0) | 2025.04.28 |
[백준] 24448 図書館 2 (Library 2) - Data Structure / Java (0) | 2025.04.27 |
[백준] 17029 Guess the Animal - Data Structure / Java (0) | 2025.04.26 |
댓글