백준/백준-C++

2503번: 숫자 야구

Beabletoet 2018. 3. 13. 09:24
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
#include<cstdio>
int main()
{
    int n, num[505], ans = 505;
    scanf("%d"&n);
    for (int i = 123, j = 0, h = 0, t = 0, o = 0; i <= 987++i)
    {
        h = i / 100;
        t = (i % 100/ 10;
        o = i % 10;
        if (h != t && t != o && h != o && h != 0 && t != 0 && o != 0)
            num[j++= i;
    }
    for (int j = 0, s, b, say, say_h, say_t, say_o; j < n; ++j)
    {
        scanf("%d %d %d"&say, &s, &b);
        say_h = say / 100;
        say_t = (say % 100/ 10;
        say_o = say % 10;
        for (int i = 0, h, t, o, s_count, b_count; i < 505++i)
            if (num[i] != 0)
            {
                h = num[i] / 100;
                t = (num[i] % 100/ 10;
                o = num[i] % 10;
                s_count = 0;
                b_count = 0;
                if (h == say_h) ++s_count;
                if (t == say_t) ++s_count;
                if (o == say_o) ++s_count;
                if (h == say_t || h == say_o) ++b_count;
                if (t == say_h || t == say_o) ++b_count;
                if (o == say_h || o == say_t) ++b_count;
                if (s_count != s || b_count != b)
                {
                    --ans;
                    num[i] = 0;
                }
            }
    }
    printf("%d", ans);
}
cs