当前位置:网站首页>L1-023 输出GPLT(Lua)
L1-023 输出GPLT(Lua)
2022-07-07 15:38:00 【有趣就行】
题目
给定一个长度不超过10000的、仅由英文字母构成的字符串。请将字符重新调整顺序,按GPLTGPLT…这样的顺序输出,并忽略其它字符。当然,四种字符(不区分大小写)的个数不一定是一样多的,若某种字符已经输出完,则余下的字符仍按GPLT的顺序打印,直到所有字符都被输出。
输入格式:
输入在一行中给出一个长度不超过10000的、仅由英文字母构成的非空字符串。
输出格式:
在一行中按题目要求输出排序后的字符串。题目保证输出非空。
输入样例:
pcTclnGloRgLrtLhgljkLhGFauPewSKgt
输出样例:
GPLTGPLTGLTGLGLL
代码
local map = {
}
local str = io.read()
str = str:upper() --转为大写
--初始化, 防止为未初始化,即为nil
map["G"], map["P"], map["L"], map["T"] = 0, 0, 0, 0
for i = 1, #str do
local ch = str:sub(i, i)
if ch == "G" or ch == "P" or ch == "L" or ch == "T" then
map[ch] = map[ch] + 1
end
end
local gplt = {
"G", "P", "L", "T"} --输出顺序
local sum = map["G"] + map["P"] + map["L"] + map["T"]
local s = "" --结果字符串
while sum > 0 do
for i = 1, 4 do
if map[gplt[i]] > 0 then
sum = sum - 1
s = s .. gplt[i]
map[gplt[i]] = map[gplt[i]] - 1
end
end
end
print(s)
边栏推荐
猜你喜欢
QML初学
Skimage learning (2) -- RGB to grayscale, RGB to HSV, histogram matching
麒麟信安操作系统衍生产品解决方案 | 存储多路径管理系统,有效提高数据传输可靠性
麒麟信安云平台全新升级!
Lowcode: four ways to help transportation companies enhance supply chain management
PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
Leetcode brush questions day49
skimage学习(1)
How to choose the appropriate automated testing tools?
Sator推出Web3游戏“Satorspace” ,并上线Huobi
随机推荐
LeetCode 120. Triangle minimum path and daily question
Mrs offline data analysis: process OBS data through Flink job
LeetCode 312. 戳气球 每日一题
MySQL implements the query of merging two fields into one field
PLC:自动纠正数据集噪声,来洗洗数据集吧 | ICLR 2021 Spotlight
LeetCode 120. 三角形最小路径和 每日一题
QT 图片背景色像素处理法
From Devops to mlops: how do it tools evolve to AI tools?
Flask搭建api服务-SQL配置文件
Flask搭建api服务
LeetCode 1986. 完成任务的最少工作时间段 每日一题
LeetCode 1696. Jumping game VI daily question
PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
QT picture background color pixel processing method
DNS 系列(一):为什么更新了 DNS 记录不生效?
Process from creation to encapsulation of custom controls in QT to toolbar (I): creation of custom controls
LeetCode 1654. 到家的最少跳跃次数 每日一题
LeetCode 1049. 最后一块石头的重量 II 每日一题
LeetCode 1626. 无矛盾的最佳球队 每日一题
Sator launched Web3 game "satorspace" and launched hoobi