3451. 字符串排序II
摘要
Title: 3451. 字符串排序II
Tag: 桶排序
Memory Limit: 64 MB
Time Limit: 1000 ms
Powered by:NEFU AB-IN
3451. 字符串排序II
-
题意
编写一个程序,将输入字符串中的字符按如下规则排序。
规则 1:英文字母从 A到 Z排列,不区分大小写。如,输入:Type 输出:epTy。
规则 2:同一个英文字母的大小写同时存在时,按照输入顺序排列。如,输入:BabA 输出:aABb。
规则 3:非英文字母的其它字符保持原来的位置。如,输入:By?e 输出:Be?y。 -
思路
将所有字母转化为数字,放到对应的桶里,最后所有字母根据字母顺序输出
-
代码
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65'''
Author: NEFU AB-IN
Date: 2023-04-26 17:27:09
FilePath: \Acwing\3451\3451.py
LastEditTime: 2023-04-26 18:06:08
'''
# import
import sys, math, os
from io import BytesIO, IOBase
from collections import Counter, deque
from heapq import heapify, heappop, heappush, nlargest, nsmallest
from bisect import bisect_left, bisect_right
from datetime import datetime, timedelta
from string import ascii_lowercase, ascii_uppercase
class sa:
def __init__(self, x, y):
self.x = x
self.y = y
def __lt__(self, x):
pass
# Final
N = int(1e3 + 10)
INF = int(2e9)
# Define
sys.setrecursionlimit(INF)
# input = lambda: sys.stdin.readline().rstrip("\r\n") # Remove when Mutiple data
read = lambda: map(int, input().split())
letterTonumber = lambda x: ord(x.upper()) - 64
# —————————————————————Division line ——————————————————————
while True:
try:
s = input()
lsts = [[] for _ in range(27)]
for i in s:
if i.isalpha():
index = letterTonumber(i)
lsts[index].append(i)
ans = []
for lst in lsts:
for i in lst:
ans.append(i)
ans = ans[::-1]
ss = ""
for i in range(len(s)):
if s[i].isalpha():
ss = ss + ans.pop()
else:
ss = ss + s[i]
print(ss)
except:
break