Skip to content

Commit c01cda2

Browse files
Add files via upload
1 parent dac2eb4 commit c01cda2

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

boj2503.java

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package java_boj;
2+
3+
import java.util.*;
4+
5+
class Baseball {
6+
7+
static LinkedList<String> curNum = new LinkedList<>();
8+
static LinkedList<String> ans = new LinkedList<>();
9+
10+
static {
11+
for(int i = 1; i<=9; i++) {
12+
for(int j = 1; j <= 9; j++) {
13+
for(int k = 1; k <= 9; k++) {
14+
if(i == j || j == k || i == k) continue;
15+
String s = i+"" + j + "" + k + "";
16+
curNum.add(s);
17+
}
18+
}
19+
}
20+
21+
}
22+
23+
static void check(String compS, int strike, int ball) {
24+
25+
int i = 0;
26+
27+
while (i < curNum.size()) {
28+
String s = curNum.get(i);
29+
// System.out.println(s);
30+
int st_count = 0;
31+
int ball_count = 0;
32+
for(int j = 0; j<3; j++) {
33+
for(int k = 0; k < 3; k++) {
34+
if(compS.charAt(j) == s.charAt(k) && j == k) {
35+
st_count++;
36+
continue;
37+
}
38+
else if(compS.charAt(j) == s.charAt(k) && j != k) {
39+
ball_count++;
40+
continue;
41+
}
42+
}
43+
}
44+
if (st_count != strike || ball_count != ball) {
45+
curNum.remove(i);
46+
i -= 1;
47+
}
48+
i += 1;
49+
}
50+
ans = curNum;
51+
//System.out.println("size : " + curNum.size());
52+
}
53+
}
54+
55+
public class boj2503 {
56+
public static void main(String[] args) {
57+
Scanner sc = new Scanner(System.in);
58+
59+
int n = sc.nextInt();
60+
sc.nextLine();
61+
62+
for(int i = 0; i<n; i++) {
63+
String s = sc.nextLine();
64+
if (Integer.parseInt(s.split(" ")[1]) == 3) {
65+
break;
66+
}
67+
Baseball.check(s.split(" ")[0], Integer.parseInt(s.split(" ")[1])
68+
, Integer.parseInt(s.split(" ")[2]));
69+
}
70+
// System.out.println(Baseball.ans);
71+
System.out.println(Baseball.ans.size());
72+
73+
}
74+
}

0 commit comments

Comments
 (0)