Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 581dd73

Browse files
Create 0423.Reconstruct Original Digits from English
1 parent e59a68f commit 581dd73

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
class Solution {
2+
public:
3+
string originalDigits(string s) {
4+
vector<int> chs(26, 0) ;
5+
vector<int> nums(10, 0) ;
6+
for (char ch: s)
7+
++chs[ch-'a'] ;
8+
9+
if (chs['z' - 'a'] != 0)
10+
{
11+
const int cnt = chs['z' - 'a'] ;
12+
chs['e' - 'a'] -= cnt ;
13+
chs['r' - 'a'] -= cnt ;
14+
chs['o' - 'a'] -= cnt ;
15+
nums[0] = cnt ;
16+
}
17+
18+
if (chs['w' - 'a'] != 0)
19+
{
20+
const int cnt = chs['w' - 'a'] ;
21+
chs['t' - 'a'] -= cnt ;
22+
chs['o' - 'a'] -= cnt ;
23+
nums[2] = cnt ;
24+
}
25+
26+
if (chs['u' - 'a'] != 0)
27+
{
28+
const int cnt = chs['u' - 'a'] ;
29+
chs['f' - 'a'] -= cnt ;
30+
chs['o' - 'a'] -= cnt ;
31+
chs['r' - 'a'] -= cnt ;
32+
nums[4] = cnt ;
33+
}
34+
35+
if (chs['x' - 'a'] != 0)
36+
{
37+
const int cnt = chs['x' - 'a'] ;
38+
chs['s' - 'a'] -= cnt ;
39+
chs['i' - 'a'] -= cnt ;
40+
nums[6] = cnt ;
41+
}
42+
43+
if (chs['g' - 'a'] != 0)
44+
{
45+
const int cnt = chs['g' - 'a'] ;
46+
chs['e' - 'a'] -= cnt ;
47+
chs['i' - 'a'] -= cnt ;
48+
chs['h' - 'a'] -= cnt ;
49+
chs['t' - 'a'] -= cnt ;
50+
nums[8] = cnt ;
51+
}
52+
53+
if (chs['o' - 'a'] != 0)
54+
{
55+
const int cnt = chs['o' - 'a'] ;
56+
chs['n' - 'a'] -= cnt ;
57+
chs['e' - 'a'] -= cnt ;
58+
nums[1] = cnt ;
59+
}
60+
61+
if (chs['t' - 'a'] != 0)
62+
{
63+
const int cnt = chs['t' - 'a'] ;
64+
chs['h' - 'a'] -= cnt ;
65+
chs['r' - 'a'] -= cnt ;
66+
chs['e' - 'a'] -= cnt*2 ;
67+
nums[3] = cnt ;
68+
}
69+
70+
if (chs['f' - 'a'] != 0)
71+
{
72+
const int cnt = chs['f' - 'a'] ;
73+
chs['i' - 'a'] -= cnt ;
74+
chs['v' - 'a'] -= cnt ;
75+
chs['e' - 'a'] -= cnt ;
76+
nums[5] = cnt ;
77+
}
78+
79+
if (chs['s' - 'a'] != 0)
80+
{
81+
const int cnt = chs['s' - 'a'] ;
82+
chs['v' - 'a'] -= cnt ;
83+
chs['n' - 'a'] -= cnt ;
84+
chs['e' - 'a'] -= cnt*2 ;
85+
nums[7] = cnt ;
86+
}
87+
88+
nums[9] = chs['i' - 'a'] ;
89+
90+
stringstream ss ;
91+
for (int i = 0; i < 10; ++i)
92+
while (nums[i]--)
93+
ss << char('0' + i) ;
94+
95+
string res ;
96+
ss >> res ;
97+
return res ;
98+
}
99+
};

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /