当前位置:网站首页>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)
边栏推荐
- Simple configuration of single arm routing and layer 3 switching
- ES6笔记一
- How to estimate the value of "not selling pens" Chenguang?
- 10 schemes to ensure interface data security
- 学习open62541 --- [67] 添加自定义Enum并显示名字
- SD_ DATA_ SEND_ SHIFT_ REGISTER
- 微信网页调试8.0.19换掉X5内核,改用xweb,所以x5调试方式已经不能用了,现在有了解决方案
- Borui data was selected in the 2022 love analysis - Panoramic report of it operation and maintenance manufacturers
- CVPR 2022 - learning non target knowledge for semantic segmentation of small samples
- 微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
猜你喜欢
随机推荐
我感觉被骗了,微信内测 “大小号” 功能,同一手机号可注册两个微信
伺服力矩控制模式下的力矩目标值(fTorque)计算
【塔望方法论】塔望3W消费战略 - U&A研究法
[unity shader] insert pass to realize the X-ray perspective effect of model occlusion
SD_ DATA_ RECEIVE_ SHIFT_ REGISTER
企业展厅设计中常用的三种多媒体技术形式
Basic operation of chain binary tree (implemented in C language)
testing and SQA_动态白盒測试[通俗易懂]
App capture of charles+postern
链式二叉树的基本操作(C语言实现)
Learn open62541 -- [67] add custom enum and display name
初识缓存以及ehcache初体验「建议收藏」
POJ 1182: food chain (parallel search) [easy to understand]
Standard ACL and extended ACL
I feel cheated. Wechat tests the function of "size number" internally, and two wechat can be registered with the same mobile number
Redis
Hutool - lightweight DB operation solution
Kirk borne's selection of learning resources this week [click the title to download directly]
POJ 2392 Space Elevator
Hongmeng smart home [1.0]



![[information security laws and regulations] review](/img/da/c9318ea8999c3ee629b0e48ab78581.png)





