当前位置:网站首页>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)
边栏推荐
- 【Seaborn】组合图表、多子图的实现
- mysql实现两个字段合并成一个字段查询
- 【视频/音频数据处理】上海道宁为您带来Elecard下载、试用、教程
- QT 图片背景色像素处理法
- LeetCode 1696. Jumping game VI daily question
- Skimage learning (1)
- mysql官网下载:Linux的mysql8.x版本(图文详解)
- Problems encountered in Jenkins' release of H5 developed by uniapp
- QT视频传输
- Establishment of solid development environment
猜你喜欢
![[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

Biped robot controlled by Arduino

Nerf: the ultimate replacement for deepfake?

With the latest Alibaba P7 technology system, mom doesn't have to worry about me looking for a job anymore

麒麟信安加入宁夏商用密码协会

User defined view essential knowledge, Android R & D post must ask 30+ advanced interview questions

QT中自定义控件的创建到封装到工具栏过程(一):自定义控件的创建

Sator推出Web3游戏“Satorspace” ,并上线Huobi

DevOps 的运营和商业利益指南

赋能智慧电力建设 | 麒麟信安高可用集群管理系统,保障用户关键业务连续性
随机推荐
How to mount the original data disk without damage after the reinstallation of proxmox ve?
【Seaborn】组合图表、多子图的实现
【图像传感器】相关双采样CDS
LeetCode 1186. 删除一次得到子数组最大和 每日一题
Flask build API service SQL configuration file
麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会
Blue Bridge Cup final XOR conversion 100 points
Flash build API service
LeetCode 120. 三角形最小路径和 每日一题
测试用例管理工具推荐
Skimage learning (3) -- gamma and log contrast adjustment, histogram equalization, coloring gray images
LeetCode 1155. 掷骰子的N种方法 每日一题
First in China! Todesk integrates RTC technology into remote desktop, with clearer image quality and smoother operation
skimage学习(3)——使灰度滤镜适应 RGB 图像、免疫组化染色分离颜色、过滤区域最大值
邮件服务器被列入黑名单,如何快速解封?
skimage学习(3)——Gamma 和 log对比度调整、直方图均衡、为灰度图像着色
skimage学习(2)——RGB转灰度、RGB 转 HSV、直方图匹配
LeetCode 1031. 两个非重叠子数组的最大和 每日一题
让保险更“保险”!麒麟信安一云多芯云桌面中标中国人寿, 助力金融保险信息技术创新发展
LeetCode 1981. 最小化目标值与所选元素的差 每日一题