-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathWordGame.java
More file actions
145 lines (108 loc) · 3.49 KB
/
WordGame.java
File metadata and controls
145 lines (108 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package spell_check;
import org.junit.jupiter.api.Test;
import java.io.*;
import java.util.*;
public class a {
// 한명만 썼다. 그럼 3점
// 두명이 썼다. 둘다 1점
// 세명이 썼다. 빵점
static InputReader r;
static int T;
static StringBuilder answer = new StringBuilder();
private static void solution() throws IOException {
int col = r.nextInt();
String[] r1 = r.nextLine().split(" ");
String[] r2 = r.nextLine().split(" ");
String[] r3 = r.nextLine().split(" ");
Map<String, Integer> map = new HashMap<>();
// r1을 map에 넣는다.
// r1의 초기 점수는 col * 3;
// 값은 1로 설정
// r2를 map에 넣는다.
// 이미 키가 존재한다면 r1 - 2, r2 + 1
// 키가 없다면 r2 + 3
// 값은 2를 더하거나 2로 설정한다.
// r3을 map에 조회한다.
// 키가 존재한다면
// -- 값이 1인지 2인지 3인지 판단한다
// ---- 값이 1이라면 r1 - 2, r3 + 1
// ---- 값이 2라면면 r2 - 2, r3 + 1
// ---- 값이 3이라면 r1 - 1, r2 - 1,
// 키가 없다면 r3 + 3
int r1s = col * 3;
int r2s = 0;
int r3s = 0;
// r1 넣기
for (String s : r1) {
map.put(s, 1);
}
// r2 넣기
for (String s : r2) {
if (map.containsKey(s)) {
r1s -= 2;
r2s += 1;
map.put(s, 3);
continue;
}
map.put(s, 2);
r2s += 3;
}
// r3 넣기
for (String s : r3) {
if (map.containsKey(s)) {
Integer value = map.get(s);
if (value == 1) {
r1s -= 2;
r3s += 1;
}
if (value == 2) {
r2s -= 2;
r3s += 1;
}
if (value == 3) {
r1s -= 1;
r2s -= 1;
}
continue;
}
r3s += 3;
}
answer.append(r1s).append(' ').append(r2s).append(' ').append(r3s).append('\n');
}
private static void input() throws IOException {
r = new InputReader("/Users/user/Downloads/boj/src/test/java/spell_check/input.txt");
T = r.nextInt();
}
@Test
public static void main(String[] args) throws IOException {
input();
for (int t = 0; t < T; t++) {
solution();
}
System.out.println(answer.toString());
}
private static class InputReader {
StringTokenizer st;
BufferedReader r;
public InputReader(String filePath) throws FileNotFoundException {
this(new FileReader(filePath));
}
public InputReader() {
this(new InputStreamReader(System.in));
}
private InputReader(InputStreamReader reader) {
r = new BufferedReader(reader);
st = new StringTokenizer("");
}
public int nextInt() throws IOException {
if (!st.hasMoreTokens()) st = new StringTokenizer(r.readLine());
return Integer.parseInt(st.nextToken());
}
public char[] nextCharArr() throws IOException {
return r.readLine().toCharArray();
}
public String nextLine() throws IOException {
return r.readLine();
}
}
}