当前位置:网站首页>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)
边栏推荐
- [image sensor] correlated double sampling CDs
- QT 图片背景色像素处理法
- LeetCode 1774. 最接近目标价格的甜点成本 每日一题
- mysql使用笔记一
- LeetCode 1981. 最小化目标值与所选元素的差 每日一题
- Smart logistics platform: make overseas warehouses smarter
- DNS series (I): why does the updated DNS record not take effect?
- The computer cannot add a domain, and the Ping domain name is displayed as the public IP. What is the problem? How to solve it?
- Leetcode brush questions day49
- MySQL usage notes 1
猜你喜欢

麒麟信安操作系统衍生产品解决方案 | 存储多路径管理系统,有效提高数据传输可靠性

How to choose the appropriate automated testing tools?

skimage学习(3)——Gamma 和 log对比度调整、直方图均衡、为灰度图像着色

Biped robot controlled by Arduino

麒麟信安云平台全新升级!

Lex & yacc of Pisa proxy SQL parsing

麒麟信安中标国网新一代调度项目!

【Seaborn】组合图表:FacetGrid、JointGrid、PairGrid

Linux 安装mysql8.X超详细图文教程

麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会
随机推荐
智慧物流平台:让海外仓更聪明
redis主从、哨兵主备切换搭建一步一步图解实现
LeetCode 1986. 完成任务的最少工作时间段 每日一题
Sator推出Web3游戏“Satorspace” ,并上线Huobi
Nerf: the ultimate replacement for deepfake?
国内首创!Todesk将RTC技术融入远程桌面,画质更清晰操作更流畅
科普达人丨一文弄懂什么是云计算?
Rpcms method of obtaining articles under the specified classification
如何在博客中添加Aplayer音乐播放器
【Seaborn】组合图表、多子图的实现
Matplotlib绘图界面设置
[image sensor] correlated double sampling CDs
Blue Bridge Cup final XOR conversion 100 points
NeRF:DeepFake的最终替代者?
Skimage learning (1)
MRS离线数据分析:通过Flink作业处理OBS数据
Solidity函数学习
《产品经理必读:五种经典的创新思维模型》的读后感
Solid function learning
LeetCode 312. 戳气球 每日一题