Cho chuỗi chữ thường s, trả về chuỗi mới với tất cả nguyên âm của s theo thứ tự tăng dần, tiếp theo là phụ âm theo thứ tự tăng dần.
Ví dụ, "helloworld" -> "eoodhlllrw", vì nguyên âm "eo", phụ âm sắp xếp "dhlllrw".
Các bước giải quyết:
k:= chuỗi rỗng,t:= chuỗi rỗng.- Duyệt từng ký tự
ctrongs:- Nếu
clà nguyên âm, nối vàok. - Ngược lại, nối vào
t.
- Nếu
- Trả về
sorted(k) + sorted(t).
Ví dụ minh họa
class Solution:
def solve(self, s):
vowels = 'aeiou'
k = ''
t = ''
for c in s:
if c in vowels:
k += c
else:
t += c
k = ''.join(sorted(k))
t = ''.join(sorted(t))
return k + t
ob = Solution()
print(ob.solve("helloworld"))
Đầu vào
"helloworld"
Đầu ra
eoodhlllrw