当前位置:网站首页>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)
边栏推荐
- In 2021, the national average salary was released. Have you reached the standard?
- 2022-07-04 matlab reads video frames and saves them
- SD_ DATA_ RECEIVE_ SHIFT_ REGISTER
- Review of network attack and defense
- Kirk borne's selection of learning resources this week [click the title to download directly]
- 【软件测试】从企业版BOSS直聘,看求职简历,你没被面上是有原因的
- 直播预约通道开启!解锁音视频应用快速上线的秘诀
- gsap动画库
- testing and SQA_动态白盒測试[通俗易懂]
- Basic operation of chain binary tree (implemented in C language)
猜你喜欢

Redis

Cadre de validation des données Apache bval réutilisé

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

如何给“不卖笔”的晨光估值?

【塔望方法论】塔望3W消费战略 - U&A研究法

Wechat web debugging 8.0.19 replace the X5 kernel with xweb, so the X5 debugging method can no longer be used. Now there is a solution

gsap动画库

我感觉被骗了,微信内测 “大小号” 功能,同一手机号可注册两个微信

Redis集群与扩展
随机推荐
UVALive – 4621 Cav 贪心 + 分析「建议收藏」
ES6笔记一
6.关于jwt
Micro service remote debug, nocalhost + rainbow micro service development second bullet
[software test] from the direct employment of the boss of the enterprise version, looking at the resume, there is a reason why you are not covered
Basic operation of chain binary tree (implemented in C language)
How to implement safety practice in software development stage
testing and SQA_动态白盒測试[通俗易懂]
企业MES制造执行系统的分类与应用
2022-07-04 matlab读取视频帧并保存
2022.07.04
2022.07.02
Antisamy: a solution against XSS attack tutorial
The top of slashdata developer tool is up to you!!!
Embedded interview questions (algorithm part)
Standard ACL and extended ACL
Wechat web debugging 8.0.19 replace the X5 kernel with xweb, so the X5 debugging method can no longer be used. Now there is a solution
Differences between rip and OSPF and configuration commands
Hutool - lightweight DB operation solution
AI来搞财富分配比人更公平?来自DeepMind的多人博弈游戏研究