-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday3a.cpp
57 lines (55 loc) · 1.1 KB
/
day3a.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
#include <bits/stdc++.h>
using namespace std;
int binaryToInt(vector<char> s)
{
int integer;
int j = 0;
for (int i = s.size() - 1; i >= 0; i--)
{
if (s[i] == '1')
{
integer += pow(2, j);
}
j++;
}
return integer;
}
int main()
{
string s;
cin >> s;
vector<vector<int>> arr(2, vector<int>(s.length(), 0));
for (int i = 0; i < s.length(); i++)
{
if (s[i] == '0')
arr[0][i]++;
else
arr[1][i]++;
}
while (cin >> s)
{
for (int i = 0; i < s.length(); i++)
{
if (s[i] == '0')
arr[0][i]++;
else
arr[1][i]++;
}
}
vector<char> gamma;
vector<char> epsilon;
for (int i = 0; i < s.length(); i++)
{
if (arr[0][i] > arr[1][i])
{
gamma.push_back('0');
epsilon.push_back('1');
}
else
{
gamma.push_back('1');
epsilon.push_back('0');
}
}
cout << binaryToInt(gamma) * binaryToInt(epsilon) << endl;
}