当前位置:网站首页>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)
边栏推荐
- Calculation of torque target value (ftorque) in servo torque control mode
- [tpm2.0 principle and Application guide] Chapter 9, 10 and 11
- Kirk borne's selection of learning resources this week [click the title to download directly]
- PTA 1101 B是A的多少倍
- The top of slashdata developer tool is up to you!!!
- [sword finger offer] 59 - I. maximum value of sliding window
- 反爬虫的重点:识别爬虫
- [tpm2.0 principle and Application guide] Chapter 16, 17 and 18
- [HDU] 5248 sequence transformation (greedy + dichotomy) [recommended collection]
- 2022上半年朋友圈都在传的10本书,找到了
猜你喜欢
随机推荐
GSAP animation library
Redis cluster and expansion
数据验证框架 Apache BVal 再使用
2022年推荐免费在线接收短信平台(国内、国外)
PV静态创建和动态创建
[Tawang methodology] Tawang 3W consumption strategy - U & a research method
How to choose the appropriate automated testing tools?
POJ 1182: food chain (parallel search) [easy to understand]
多个kubernetes集群如何实现共享同一个存储
【Base64笔记】「建议收藏」
反爬虫的重点:识别爬虫
Complete e-commerce system
testing and SQA_动态白盒測试[通俗易懂]
Reject policy of thread pool
初识缓存以及ehcache初体验「建议收藏」
For friends who are not fat at all, nature tells you the reason: it is a genetic mutation
Borui data was selected in the 2022 love analysis - Panoramic report of it operation and maintenance manufacturers
LeetCode 497(C#)
6.关于jwt
Tapdata 的 2.0 版 ,开源的 Live Data Platform 现已发布



![学习open62541 --- [67] 添加自定义Enum并显示名字](/img/98/e5e25af90b3f98c2be11d7d21e5ea6.png)





