# [LeetCode] Reconstruct Original Digits from English 从英文中重建数字

+关注继续查看

Given a non-empty string containing an out-of-order English representation of digits 0-9, output the digits in ascending order.

Note:

1. Input contains only lowercase English letters.
2. Input is guaranteed to be valid and can be transformed to its original digits. That means invalid inputs such as "abc" or "zerone" are not permitted.
3. Input length is less than 50,000.

Example 1:

Input: "owoztneoer"
Output: "012"

Example 2:

Input: "fviefuro"
Output: "45"

class Solution {
public:
string originalDigits(string s) {
string res = "";
vector<string> words{"zero", "two", "four", "six", "eight", "one", "three", "five", "seven", "nine"};
vector<int> nums{0, 2, 4, 6, 8, 1, 3, 5, 7, 9}, counts(26, 0);
vector<char> chars{'z', 'w', 'u', 'x', 'g', 'o', 'h', 'f', 's', 'i'};
for (char c : s) ++counts[c - 'a'];
for (int i = 0; i < 10; ++i) {
int cnt = counts[chars[i] - 'a'];
for (int j = 0; j < words[i].size(); ++j) {
counts[words[i][j] - 'a'] -= cnt;
}
while (cnt--) res += (nums[i] + '0');
}
sort(res.begin(), res.end());
return res;
}
};

class Solution {
public:
string originalDigits(string s) {
string res = "";
vector<int> counts(128, 0), nums(10, 0);
for (char c : s) ++counts[c];
nums[0] = counts['z'];
nums[2] = counts['w'];
nums[4] = counts['u'];
nums[6] = counts['x'];
nums[8] = counts['g'];
nums[1] = counts['o'] - nums[0] - nums[2] - nums[4];
nums[3] = counts['h'] - nums[8];
nums[5] = counts['f'] - nums[4];
nums[7] = counts['s'] - nums[6];
nums[9] = counts['i'] - nums[6] - nums[8] - nums[5];
for (int i = 0; i < nums.size(); ++i) {
for (int j = 0; j < nums[i]; ++j) {
res += (i + '0');
}
}
return res;
}
};

10092 0
EasyUI表单验证，自定义插件验证，自定义js插件验证，远程验证，常见手机号，中英文，qq等验证规则验证
﻿﻿  {                       field : 'startPort',                       title : "起始端口",                       editor: "text",                       width : 50,                       editor: {
1810 0
ASCII,Utf8,Unicode编码下的中英文字符大小
一，测试Demo namespace 不同编码下的中英文字符大小 { class Program { static void Main(string[] args) { ShowCode()...
671 0
Word中插入英文格式的算法流程
如图上部分所示，需要序号自动编号，那么插入一个一行一列的的表格，然后点击编号，使得项目自动编号，编号一个就在后面输入一些内容，按enter后第二行开始自动编号，如果要缩进，不能按Tab，Tab自动创建下一行，用两个空格。
3150 0

936 0

13893 0
C#语言之“中英文混合字符串对齐”的方法【转】

786 0

7365 0
+关注

2107

1103

《2021云上架构与运维峰会演讲合集》

《零基础CSS入门教程》

《零基础HTML入门教程》