-
Notifications
You must be signed in to change notification settings - Fork 359
/
s1.cpp
30 lines (30 loc) · 781 Bytes
/
s1.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
class Solution {
private:
map<char, int> cnts;
vector<int> cs;
string ans;
void helper(char c, string s, int i) {
int cnt = cnts[c];
for (char c : s) cnts[c] -= cnt;
cs[i] = cnt;
}
public:
string originalDigits(string s) {
cs = vector<int>(10, 0);
for (char c : s) cnts[c]++;
helper('z', "zero", 0);
helper('w', "two", 2);
helper('u', "four", 4);
helper('x', "six", 6);
helper('g', "eight", 8);
helper('o', "one", 1);
helper('h', "three", 3);
helper('f', "five", 5);
helper('s', "seven", 7);
helper('i', "nine", 9);
for (int i = 0; i <= 9; ++i) {
while (cs[i]--) ans += '0' + i;
}
return ans;
}
};