summaryrefslogtreecommitdiff
path: root/3.c
blob: 39db01d34c52b15e9ff581c56499d899ffba6e81 (plain)
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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

static int FromBin(const char *p)
{
    int b = strlen(p) - 1;
    int v = 0;
    int f;

    for(f = 0; p[f]; f++, b--)
    {
        if (p[f] == '1')
        {
            v |= 1 << b;
        }
    }

    return v;
}

int main(void)
{
    char buff[80];
    int bit[12] = {0};
    int count = 0;
    char str[13] = {0};
    int f;
    int gamma, epsilon;

    while(fgets(buff, sizeof buff, stdin))
    {
        for(f = 0; f < 12; f++)
        {
            if (buff[f] == '1')
            {
                bit[f]++;
            }
        }

        count++;
    }

    for(f = 0; f < 12; f++)
    {
        if (bit[f] > count / 2)
        {
            str[f] = '1';
        }
        else
        {
            str[f] = '0';
        }
    }

    gamma = FromBin(str);

    for(f = 0; f < 12; f++)
    {
        if (str[f] == '0')
        {
            str[f] = '1';
        }
        else
        {
            str[f] = '0';
        }
    }

    epsilon = FromBin(str);

    printf("%d\n", gamma * epsilon);

    return 0;
}