-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2503_숫자야구.cpp
95 lines (76 loc) · 1.65 KB
/
2503_숫자야구.cpp
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
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
vector<int> v;
vector<pair<int, int> > pv;
int result = 0;
bool checkNum(int nomineeNum, int askNum, int s, int b) {
int tempS = 0, tempB = 0;
int nomineeDigit[3];
int askNumDigit[3];
nomineeDigit[0] = nomineeNum / 100;
askNumDigit[0] = askNum / 100;
nomineeDigit[1] = nomineeNum / 10 % 10;
askNumDigit[1] = askNum / 10 % 10;
nomineeDigit[2] = nomineeNum % 10;
askNumDigit[2] = askNum % 10;
if (nomineeDigit[0] == nomineeDigit[1] ||
nomineeDigit[0] == nomineeDigit[2] ||
nomineeDigit[1] == nomineeDigit[2]) {
return false;
}
if (nomineeDigit[0] == 0 || nomineeDigit[1] == 0 || nomineeDigit[2] == 0) {
return false;
}
for (int i = 0; i < 3; i++) {
if (nomineeDigit[i] == askNumDigit[i]) {
tempS++;
}
}
// 123 324
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i != j) {
if (nomineeDigit[i] == askNumDigit[j]) {
tempB++;
}
}
}
}
if (tempS == s && tempB == b) {
return true;
} else {
return false;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
v.push_back(temp);
int s, b;
cin >> s >> b;
pv.push_back(make_pair(s, b));
}
for (int i = 123; i <= 987; i++) {
int valid = 1;
for (int j = 0; j < n; j++) {
if (!checkNum(i, v[j], pv[j].first, pv[j].second)) {
valid = 0;
break;
}
}
if (valid) {
result++;
}
}
cout << result;
return 0;
}