-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCloseMatch.cpp
More file actions
146 lines (139 loc) · 2.68 KB
/
CloseMatch.cpp
File metadata and controls
146 lines (139 loc) · 2.68 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* Google Code Jam 2016 Round 1B 1
* Coded by Ziyi Tang, New York University CS480 APS S16
* Observation
*/
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
const int INF = (int)1E9;
const long INFL = (long)1E18;
const int dir[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
#define REP(i,s,t) for(int i=(s);i<(t);i++)
#define FILL(x,v) memset(x,v,sizeof(x))
#define MAXN 1000
#define MOD 1000000007
int all[30];
vector<int> re;
int main(){
int test;
cin >> test;
REP(t,1,test+1){
FILL(all,0);
re.clear();
string line;
cin >> line;
int sz = line.size();
REP(i,0,sz){
all[line[i]-'A'] += 1;
}
int six = all['X'-'A'];
all['S'-'A']-=six;
all['I'-'A']-=six;
all['X'-'A']-=six;
REP(i,0,six){
re.push_back(6);
}
int two = all['W'-'A'];
all['T'-'A']-=two;
all['W'-'A']-=two;
all['O'-'A']-=two;
REP(i,0,two){
re.push_back(2);
}
int four = all['U'-'A'];
all['F'-'A']-=four;
all['O'-'A']-=four;
all['U'-'A']-=four;
all['R'-'A']-=four;
REP(i,0,four){
re.push_back(4);
}
int five = all['F'-'A'];
all['F'-'A']-=five;
all['I'-'A']-=five;
all['V'-'A']-=five;
all['E'-'A']-=five;
REP(i,0,five){
re.push_back(5);
}
int eight = all['G'-'A'];
all['E'-'A']-=eight;
all['I'-'A']-=eight;
all['G'-'A']-=eight;
all['H'-'A']-=eight;
all['T'-'A']-=eight;
REP(i,0,eight){
re.push_back(8);
}
int zero = all['Z'-'A'];
all['Z'-'A']-=zero;
all['E'-'A']-=zero;
all['R'-'A']-=zero;
all['O'-'A']-=zero;
REP(i,0,zero){
re.push_back(0);
}
int one = all['O'-'A'];
all['O'-'A']-=one;
all['N'-'A']-=one;
all['E'-'A']-=one;
REP(i,0,one){
re.push_back(1);
}
int seven = all['S'-'A'];
all['S'-'A']-=seven;
all['E'-'A']-=seven;
all['E'-'A']-=seven;
all['V'-'A']-=seven;
all['N'-'A']-=seven;
REP(i,0,seven){
re.push_back(7);
}
int nine = all['I'-'A'];
all['N'-'A']-=nine;
all['I'-'A']-=nine;
all['N'-'A']-=nine;
all['E'-'A']-=nine;
REP(i,0,nine){
re.push_back(9);
}
int three = all['T'-'A'];
all['T'-'A']-=three;
all['T'-'A']-=three;
all['T'-'A']-=three;
all['T'-'A']-=three;
all['T'-'A']-=three;
REP(i,0,three){
re.push_back(3);
}
sort(re.begin(),re.end());
printf("Case #%d: ", t);
int ssz = re.size();
REP(i,0,ssz){
cout << re[i];
}
cout << endl;
}
return 0;
}