forked from b-chae/AlgorithmStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1107.cpp
More file actions
47 lines (41 loc) · 693 Bytes
/
Copy path1107.cpp
File metadata and controls
47 lines (41 loc) · 693 Bytes
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
#include <iostream>
#include <cmath>
using namespace std;
bool broken[10];
int check(int n)
{
int res = 0;
if (n == 0 && broken[0])
return 0;
else if (n == 0)
return 1;
while (n > 0)
{
if (broken[n % 10])
return 0;
n = n / 10;
res++;
}
return res;
}
int main()
{
int i, N, M, x;
cin >> N >> M;
for (i = 0; i < M; i++)
{
cin >> x;
broken[x] = true;
}
int ans = abs(N - 100);
for (i = 0; i <= 1000000; i++)
{
x = check(i);
if (x > 0)
{
ans = min(ans, x + abs(N - i));
}
}
cout << ans << "\n";
return 0;
}