当前位置:网站首页>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)
边栏推荐
- AI来搞财富分配比人更公平?来自DeepMind的多人博弈游戏研究
- LeetCode 1186. Delete once to get the sub array maximum and daily question
- 【视频/音频数据处理】上海道宁为您带来Elecard下载、试用、教程
- Shallow understanding Net core routing
- Process from creation to encapsulation of custom controls in QT to toolbar (I): creation of custom controls
- 【Seaborn】组合图表、多子图的实现
- skimage学习(1)
- LeetCode 300. Daily question of the longest increasing subsequence
- DNS series (I): why does the updated DNS record not take effect?
- Siggraph 2022 best technical paper award comes out! Chen Baoquan team of Peking University was nominated for honorary nomination
猜你喜欢
![[video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial](/img/14/4e7ebfb1ed5b99f8377af9d17d2177.jpg)
[video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial

DevOps 的运营和商业利益指南

麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会

Shallow understanding Net core routing
Share the latest high-frequency Android interview questions, and take you to explore the Android event distribution mechanism

Pycharm IDE下载

《产品经理必读:五种经典的创新思维模型》的读后感

Test case management tool recommendation

A tour of grpc:03 - proto serialization / deserialization

Matplotlib绘制三维图形
随机推荐
Sator推出Web3游戏“Satorspace” ,并上线Huobi
[Seaborn] implementation of combined charts and multi subgraphs
PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
QT picture background color pixel processing method
LeetCode 1477. Find two subarrays with sum as the target value and no overlap
mysql使用笔记一
rpcms获取指定分类下的文章的方法
QT 图片背景色像素处理法
DNS series (I): why does the updated DNS record not take effect?
DevOps 的运营和商业利益指南
《产品经理必读:五种经典的创新思维模型》的读后感
How to add aplayer music player in blog
centos7安装mysql笔记
Jenkins发布uniapp开发的H5遇到的问题
Pycharm IDE下载
Sator launched Web3 game "satorspace" and launched hoobi
麒麟信安加入宁夏商用密码协会
麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会
Reflections on "product managers must read: five classic innovative thinking models"
LeetCode 1986. 完成任务的最少工作时间段 每日一题