728x90
300x250
https://www.acmicpc.net/problem/2503
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Boj2503 {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
System.setIn(new FileInputStream("Test.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int comp[][] = new int[N][3];
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
comp[i][0] = Integer.parseInt(st.nextToken());
comp[i][1] = Integer.parseInt(st.nextToken());
comp[i][2] = Integer.parseInt(st.nextToken());
}
int res = 0;
for (int i = 1; i < 10; i++) {
for (int j = 1; j < 10; j++) {
for (int k = 1; k < 10; k++) {
if (i == j || j == k || i == k)
continue;
String std = "" + i + j + k;
boolean flag = true;
//// 조건을 만족하는지 체크
for (int tc = 0; tc < N; tc++) {
int cntS = 0;
int cntB = 0;
String compStr = String.valueOf(comp[tc][0]);
// 자릿수 비교
for (int l = 0; l < 3; l++) {
if (std.charAt(l) == compStr.charAt(l)) {
cntS++;
} else if (std.contains(compStr.charAt(l) + "")) {
cntB++;
}
}
//검증
if (cntS != comp[tc][1] || cntB != comp[tc][2]) {
flag = false;
break;
}
}
if (flag)
res++;
}
}
}
System.out.println(res);
}
}
728x90
'알고리즘 > 그 외' 카테고리의 다른 글
백준 10845번: 큐 [큐][Queue][자료구조] -Java (0) | 2023.11.13 |
---|---|
백준 1764번: 듣보잡 [자료구조][정렬][문자열] -Java (0) | 2023.11.06 |
백준 1406번: 에디터 [자료구조][리스트] -Java (0) | 2023.09.30 |
백준 1931번: 회의실 배정 [정렬][그리디][Greedy] -Java (0) | 2023.07.31 |
백준 2910번: 빈도 정렬 [정렬][Map] - Java (0) | 2023.07.25 |