当前位置:网站首页>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)
边栏推荐
- Pychart ide Download
- 【图像传感器】相关双采样CDS
- QML初学
- [Seaborn] combination chart: pairplot and jointplot
- 【Seaborn】组合图表:PairPlot和JointPlot
- 99% of users often make mistakes in power Bi cloud reports
- LeetCode 1155. 掷骰子的N种方法 每日一题
- How to choose the appropriate automated testing tools?
- Lex & yacc of Pisa proxy SQL parsing
- [video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial
猜你喜欢

mysql官网下载:Linux的mysql8.x版本(图文详解)

管理VDI的几个最佳实践

Sator a lancé le jeu web 3 "satorspace" et a lancé huobi

如何在博客中添加Aplayer音乐播放器

Lex & yacc of Pisa proxy SQL parsing

QT picture background color pixel processing method

Lowcode: four ways to help transportation companies enhance supply chain management

自定义View必备知识,Android研发岗必问30+道高级面试题

The process of creating custom controls in QT to encapsulating them into toolbars (II): encapsulating custom controls into toolbars

Sator推出Web3遊戲“Satorspace” ,並上線Huobi
随机推荐
MySQL implements the query of merging two fields into one field
LeetCode 1696. Jumping game VI daily question
LeetCode 1626. The best team without contradiction
DNS 系列(一):为什么更新了 DNS 记录不生效?
服务器彻底坏了,无法修复,如何利用备份无损恢复成虚拟机?
User defined view essential knowledge, Android R & D post must ask 30+ advanced interview questions
[video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial
Jenkins发布uniapp开发的H5遇到的问题
DevOps 的运营和商业利益指南
Read PG in data warehouse in one article_ stat
mysql实现两个字段合并成一个字段查询
LeetCode 312. Poke balloon daily
99% 用户在 Power BI 云端报表常犯错误
LeetCode 1696. 跳跃游戏 VI 每日一题
【Seaborn】组合图表、多子图的实现
【饭谈】如何设计好一款测试平台?
浅浅理解.net core的路由
防火墙系统崩溃、文件丢失的修复方法,材料成本0元
Solid function learning
从DevOps到MLOps:IT工具怎样向AI工具进化?