-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathma_gray3.cpp
More file actions
40 lines (40 loc) · 890 Bytes
/
ma_gray3.cpp
File metadata and controls
40 lines (40 loc) · 890 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
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
int main()
{
vector<vector<string>> ans;
vector<string> a;
a.push_back("0");
a.push_back("1");
ans.push_back(a);
for (int i = 0; i < 9; i++)
{
a.clear();
for (int j = 0; j < ans[i].size(); j++)
{
a.push_back('0' + ans[i][j]);
}
for (int j = ans[i].size() - 1; j >= 0; j--)
{
a.push_back('1' + ans[i][j]);
}
ans.push_back(a);
}
int t;
cin >> t;
while (t--)
{
string s;
cin >> s;
long long k = 0;
for (int i = s.length() - 1; i >= 0; i--)
{
if (s[i] == '1')
{
k += (1 << (s.length() - 1 - i));
}
}
cout << ans[s.length() - 1][k] << endl;
}
}