当前位置:网站首页>L1-023 output gplt (Lua)
L1-023 output gplt (Lua)
2022-07-07 19:13:00 【Just be interesting】
subject
A given length does not exceed 10000 Of 、 A string consisting only of English letters . Please reorder the characters , Press GPLTGPLT… Output in this order , And ignore the other characters . Of course , Four types of characters ( Case insensitive ) It doesn't have to be the same number , If a character has been printed out , Then press the remaining characters GPLT Sequential printing , Until all characters are printed .
Input format :
The input is given in a line with a length not exceeding 10000 Of 、 A non - empty string consisting only of English letters .
Output format :
Output the sorted string on a line by the title . The question guarantees that the output is not empty .
sample input :
pcTclnGloRgLrtLhgljkLhGFauPewSKgt
sample output :
GPLTGPLTGLTGLGLL
Code
local map = {
}
local str = io.read()
str = str:upper() -- Capitalize
-- initialization , Prevent uninitialized , That is to say 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"} -- Output order
local sum = map["G"] + map["P"] + map["L"] + map["T"]
local s = "" -- Result string
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)
边栏推荐
- ES6笔记一
- SD_ DATA_ SEND_ SHIFT_ REGISTER
- 【HDU】5248-序列变换(贪心+二分)「建议收藏」
- Scientists have observed for the first time that the "electron vortex" helps to design more efficient electronic products
- Embedded interview questions (algorithm part)
- Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind
- 直播预约通道开启!解锁音视频应用快速上线的秘诀
- 微信网页调试8.0.19换掉X5内核,改用xweb,所以x5调试方式已经不能用了,现在有了解决方案
- AI写首诗
- 学习open62541 --- [67] 添加自定义Enum并显示名字
猜你喜欢
cmd命令进入MySQL时报服务名或者命令错误(傻瓜式教学)
企业展厅设计中常用的三种多媒体技术形式
6. About JWT
Basic concepts and properties of binary tree
Short selling, overprinting and stock keeping, Oriental selection actually sold 2.66 million books in Tiktok in one month
SlashData开发者工具榜首等你而定!!!
App capture of charles+postern
How to choose the appropriate automated testing tools?
Charles+Postern的APP抓包
伺服力矩控制模式下的力矩目标值(fTorque)计算
随机推荐
Borui data was selected in the 2022 love analysis - Panoramic report of it operation and maintenance manufacturers
Charles+Postern的APP抓包
2022.07.02
POJ 1182: food chain (parallel search) [easy to understand]
How to implement safety practice in software development stage
Flipping game (enumeration)
數據驗證框架 Apache BVal 再使用
[mime notes]
50亿,福建又诞生一只母基金
I feel cheated. Wechat tests the function of "size number" internally, and two wechat can be registered with the same mobile number
"Decryption" Huawei machine vision Corps: Huawei is moving up and the industry is moving forward
Basic concepts and properties of binary tree
SD_ DATA_ SEND_ SHIFT_ REGISTER
2022-07-04 matlab读取视频帧并保存
LeetCode 497(C#)
【HDU】5248-序列变换(贪心+二分)「建议收藏」
First time in China! The language AI strength of this Chinese enterprise is recognized as No.2 in the world! Second only to Google
线程池的拒绝策略
Reject policy of thread pool
Nat address translation