• 문제 링크
https://www.acmicpc.net/problem/5134
• 풀이 코드
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));
StringBuilder sb = new StringBuilder();
Map<String, Integer> a = new HashMap<>();
Map<String, Double> b = new HashMap<>();
int t = Integer.parseInt(br.readLine());
for (int tc = 1; tc <= t; tc++) {
String s = br.readLine();
int i = s.indexOf(' ');
int n = Integer.parseInt(s.substring(0, i)), m = Integer.parseInt(s.substring(i + 1));
while (n-- > 0) register(br.readLine(), a, b);
double sum = 0;
while (m-- > 0) {
s = br.readLine();
i = s.indexOf(' ');
String key = s.substring(i + 1).toLowerCase();
if (b.containsKey(key)) sum += b.get(key) * Math.min(Integer.parseInt(s.substring(0, i)), a.get(key));
}
sb.append("Data Set ").append(tc).append(String.format(":\n$%.2f\n\n", sum));
a.clear();
b.clear();
}
bw.write(sb.toString());
bw.flush();
}
private static void register(String s, Map<String, Integer> a, Map<String, Double> b) {
int i = s.indexOf(' '), j = s.indexOf(' ', i + 1), k = s.indexOf(' ', j + 1);
String key = s.substring(k + 1).toLowerCase();
a.put(key, Integer.parseInt(s.substring(0, i)));
b.put(key, Double.parseDouble(s.substring(i + 2, j)) - Double.parseDouble(s.substring(j + 2, k)));
}
}'Problem Solving > Baekjoon' 카테고리의 다른 글
| [백준] 2576 홀수 - Implementation / Java (0) | 2025.12.28 |
|---|---|
| [백준] 14670 병약한 영정 - Data Structure / Java (0) | 2025.12.26 |
| [백준] 34692 아 마이마이 하고 싶다 - Data Structure / Java (0) | 2025.12.25 |
| [백준] 30949 Equal Schedules - Data Structure / Java (0) | 2025.12.24 |
| [백준] 25757 임스와 함께하는 미니게임 - Data Structure / Java (0) | 2025.12.23 |
댓글