0. 문제 |
1. 아이디어 |
1) 123부터 987까지의 모든 수들 중에서, 주어진 N개의 질문에 대해 같은 결과를 가지는 수를 카운트한다.
2. 소스코드 |
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
|
#include <iostream>
#include <string>
#include <vector>
struct entry
{
std::string num;
int strike;
int ball;
};
int main()
{
int N;
std::cin >> N;
std::vector<entry> entryV;
for (int i = 0; i < N; i++)
{
entry input;
std::cin >> input.num >> input.strike >> input.ball;
entryV.push_back(input);
}
int result = 0;
for (int i = 123; i <= 987; i++)
{
int temp = 0;
std::string target = std::to_string(i);
if (target[0] == '0' || target[1] == '0' || target[2] == '0' || target[0] == target[1] || target[1] == target[2] || target[2] == target[0])
continue;
for (int j = 0; j < N; j++)
{
int temps = 0, tempb = 0;
for (int k = 0; k < 3; k++)
{
if (entryV[j].num[k] == target[k]) temps++;
else if (target[k] == entryV[j].num[(k + 1) % 3] || target[k] == entryV[j].num[(k + 2) % 3])
tempb++;
}
if (temps == entryV[j].strike && tempb == entryV[j].ball) temp++;
}
if (temp == N) result++;
}
std::cout << result;
}
|
cs |
3. 결과 |
4. 피드백 |
- 혼자서 못 풀었다..
- 브루트 포스는 결국 주어진 모든 조건들에 대해서 만족하는 경우의 수를 찾는 방법이구나.
'알고리즘 > BOJ' 카테고리의 다른 글
[C++] 백준 1182번 - 부분수열의 합 (0) | 2020.03.06 |
---|---|
[C++] 백준 1018번 - 체스판 다시 칠하기 (0) | 2020.03.05 |
[C++] 백준 10448번 - 유레카 이론 (0) | 2020.03.01 |
[C++] 백준 3085번 - 사탕 게임 (0) | 2020.03.01 |
[C++] 백준 2231번 - 분해합 (0) | 2020.02.29 |