-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChef and Pick Digit
82 lines (78 loc) Β· 1.73 KB
/
Chef and Pick Digit
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
76
77
78
79
80
81
82
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
#define MP make_pair;
#define vt vector
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define REP(i, a) for (int i = 0; i < a; i++)
#define pii pair<int, int>;
#define pll pair<ll, ll>;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pl;
void solve()
{
string s;
cin >> s;
set<int> se;
map<int,int> m;
for (int i = 0; i < s.size(); i++) {
se.insert((int)s[i]-48);
m[(int)s[i]-48]++;
}
for (auto e : se) {
if (e==6) {
for (auto f : se) {
if (f>=5) {
if (e!=f) {
cout << char(e*10+f);
}
else if (e==f&&m[e]>=2) {
cout << char(e*10+f);
}
}
}
}
else if (e==9) {
for (auto f : se) {
if (f==0) {
cout << 'Z';
break;
}
else {
break;
}
}
}
else if (e>6) {
for (auto f : se) {
if (e!=f) {
cout << char(e*10+f);
}
else if (e==f&&m[e]>=2) {
cout << char(e*10+f);
}
}
}
}
cout << endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
ll t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}