当前位置:网站首页>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)
边栏推荐
- 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 1155. 掷骰子的N种方法 每日一题
- Pycharm IDE下载
- 麒麟信安云平台全新升级!
- Flash build API Service - generate API documents
- Flask搭建api服务-生成API文档
- QT picture background color pixel processing method
- 无法链接远程redis服务器(解决办法百分百)
- The process of creating custom controls in QT to encapsulating them into toolbars (II): encapsulating custom controls into toolbars
- MRS离线数据分析:通过Flink作业处理OBS数据
猜你喜欢
Siggraph 2022 best technical paper award comes out! Chen Baoquan team of Peking University was nominated for honorary nomination
How to add aplayer music player in blog
Linux 安装mysql8.X超详细图文教程
科普达人丨一文弄懂什么是云计算?
MRS离线数据分析:通过Flink作业处理OBS数据
麒麟信安中标国网新一代调度项目!
mysql官网下载:Linux的mysql8.x版本(图文详解)
Skimage learning (3) -- gamma and log contrast adjustment, histogram equalization, coloring gray images
Sator推出Web3游戏“Satorspace” ,并上线Huobi
What is cloud computing?
随机推荐
LeetCode 152. Product maximum subarray daily question
LeetCode 300. 最长递增子序列 每日一题
QT视频传输
[Seaborn] implementation of combined charts and multi subgraphs
SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名
第九届 蓝桥杯 决赛 交换次数
Smart logistics platform: make overseas warehouses smarter
DAPP defi NFT LP single and dual currency liquidity mining system development details and source code
LeetCode 1626. The best team without contradiction
LeetCode 152. 乘积最大子数组 每日一题
如何在软件研发阶段落地安全实践
无法链接远程redis服务器(解决办法百分百)
LeetCode 1696. 跳跃游戏 VI 每日一题
LeetCode 213. 打家劫舍 II 每日一题
DNS series (I): why does the updated DNS record not take effect?
[Huang ah code] Why do I suggest you choose go instead of PHP?
【源码解读】| LiveListenerBus源码解读
Process from creation to encapsulation of custom controls in QT to toolbar (I): creation of custom controls
LeetCode 312. Poke balloon daily
Sator推出Web3遊戲“Satorspace” ,並上線Huobi