• 문제 링크
10105번: Assigning Partners
The input consists of three lines. The first line consists of an integer N (1 < N ≤ 30), which is the number of students in the class. The second line contains the first names of the N students separated by single spaces. (Names contain only uppercase or
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;
import java.util.StringTokenizer;
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));
bw.write(isGood(Integer.parseInt(br.readLine()), new StringTokenizer(br.readLine()), new StringTokenizer(br.readLine())) ? "good" : "bad");
bw.flush();
}
private static boolean isGood(int n, StringTokenizer a, StringTokenizer b) {
Map<String, String> map = new HashMap<>();
while (n-- > 0) {
String key = a.nextToken(), value = b.nextToken();
if (key.equals(value)) return false;
if (map.containsKey(value) && !map.get(value).equals(key)) return false;
map.put(key, value);
}
return true;
}
}'Problem Solving > Baekjoon' 카테고리의 다른 글
| [백준] 18294 Biodiversity - Data Structure / Java (0) | 2023.11.04 |
|---|---|
| [백준] 4881 자리수의 제곱 - Data Structure / Java (0) | 2023.11.03 |
| [백준] 9728 Pair Sum - Data Structure / Java (0) | 2023.11.01 |
| [백준] 13211 Passport Checking - Data Structure / Java (0) | 2023.10.31 |
| [백준] 20170 Commemorative Dice - Brute Force / Java (0) | 2023.10.30 |
댓글