当前位置:网站首页>L1-027 rental (Lua)
L1-027 rental (Lua)
2022-07-07 19:20:00 【Just be interesting】
subject
At one time, the Internet was full of cries for help , How to break this . In fact, this code is very simple ,index Array is arr Index of the array ,index[0]=2 Corresponding arr[2]=1,index[1]=0 Corresponding arr[0]=8,index[2]=3 Corresponding arr[3]=0, And so on …… It's easy to get a phone number 18013820100.
This question asks you to write a program , Generate this code for any phone number —— in fact , Just generate the first two lines , The rest is the same .
Input format :
Type in a line to give a result of 11 A cell phone number made up of digits .
Output format :
Generate the first two lines of code for the entered number , among arr The numbers in must be given in descending order .
sample input :
18013820100
sample output :
int[] arr = new int[]{8,3,2,1,0};
int[] index = new int[]{3,0,4,3,1,0,2,4,3,4,4};
Code
local arr = {
}
local s = io.read()
for i = 1, #s do
idx = tonumber(s:sub(i, i))
arr[idx] = 1
end
local s1, s2 = "int[] arr = new int[]{", "int[] index = new int[]{"
local map = {
}
local len = 0
for i = 9, 0, -1 do
if arr[i] then
map[i] = len
len = len + 1
s1 = s1 .. i .. ","
end
end
s1 = s1:sub(1, #s1 - 1) .. "};"
for i = 1, #s do
s2 = s2 .. map[tonumber(s:sub(i, i))] .. ","
end
s2 = s2:sub(1, #s2 - 1) .. "};"
print(s1)
print(s2)
边栏推荐
- POJ 2392 Space Elevator
- Zhong Xuegao wants to remain innocent in the world
- 2022.07.02
- 前首富,沉迷种田
- 2022上半年朋友圈都在传的10本书,找到了
- testing and SQA_ Dynamic white box test [easy to understand]
- 网易云信参与中国信通院《实时音视频服务(RTC)基础能力要求及评估方法》标准编制...
- 10 schemes to ensure interface data security
- DeSci:去中心化科学是Web3.0的新趋势?
- How to choose the appropriate automated testing tools?
猜你喜欢
Tips and tricks of image segmentation summarized from 39 Kabul competitions
6. About JWT
Policy mode - unity
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
Pasqal首席技术官:模拟量子计算率先为工业带来量子优势
SlashData开发者工具榜首等你而定!!!
基于图像和激光的多模态点云融合与视觉定位
前首富,沉迷种田
2022.07.04
DeSci:去中心化科学是Web3.0的新趋势?
随机推荐
【牛客网刷题系列 之 Verilog进阶挑战】~ 多bit MUX同步器
解决rosdep的报错问题
超分辨率技术在实时音视频领域的研究与实践
[mime notes]
L1-023 output gplt (Lua)
【MIME笔记】
L1-028 judging prime number (Lua)
Seize Jay Chou
最长公共前缀(leetcode题14)
Flipping Game(枚举)
Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind
杰理之关于 TWS 交叉配对的配置【篇】
Experiment 1 of Compilation Principle: automatic implementation of lexical analyzer (Lex lexical analysis)
2022.07.04
Redis
First time in China! The language AI strength of this Chinese enterprise is recognized as No.2 in the world! Second only to Google
Learn open62541 -- [67] add custom enum and display name
Number - number (Lua)
Multimodal point cloud fusion and visual location based on image and laser
POJ 2392 Space Elevator