1.问题描述:
Given a non-empty string containing an out-of-order English representation of digits 0-9, output the digits in ascending order.
Note:
Input contains only lowercase English letters.
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.
Input length is less than 50,000.
Example 1:
Input: “owoztneoer”
Output: “012”
Example 2:
Input: “fviefuro”
Output: “45”
Note:
Input contains only lowercase English letters.
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.
Input length is less than 50,000.
Example 1:
Input: “owoztneoer”
Output: “012”
Example 2:
Input: “fviefuro”
Output: “45”
2.Python实现:
#-*- coding:utf-8 -*-
def originalDigitals(s):
L=[x*0 for x in range(10)]
for i in s:
if i=='z':
L[0]+=1
if i=='w':
L[2]+=1
if i=='u':
L[4]+=1
if i=='x':
L[6]+=1
if i=='g':
L[8]+=1
if i=='o':
L[1]+=1
if i=='h':
L[3]+=1
if i=='f':
L[5]+=1
if i=='s':
L[7]+=1
if i=='i':
L[9]+=1
L[1]=L[1]-L[0]-L[2]-L[4]
L[3]=L[3]-L[8]
L[5]=L[5]-L[4]
L[7]=L[7]-L[6]
L[9]=L[9]-L[4]-L[6]-L[8]
Result=[]
for index,value in enumerate(L):
for j in range(value):
Result.append(index)
return Result
if __name__=="__main__":
s=input('input a string:')
result=originalDigitals(s)
print (result)