当前位置:网站首页>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)
边栏推荐
- 杰理之关于 TWS 交叉配对的配置【篇】
- How to share the same storage among multiple kubernetes clusters
- Antisamy: a solution against XSS attack tutorial
- PV static creation and dynamic creation
- Numpy——2.数组的形状
- IP netns command (memo)
- LeetCode 515(C#)
- How to choose the appropriate automated testing tools?
- A hodgepodge of ICER knowledge points (attached with a large number of topics, which are constantly being updated)
- In the first half of 2022, I found 10 books that have been passed around by my circle of friends
猜你喜欢
Numpy——2.数组的形状
Tapdata 的 2.0 版 ,开源的 Live Data Platform 现已发布
Cadre de validation des données Apache bval réutilisé
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
2022.07.02
Command mode - unity
Continuous test (CT) practical experience sharing
Desci: is decentralized science the new trend of Web3.0?
How to share the same storage among multiple kubernetes clusters
Policy mode - unity
随机推荐
IP netns command (memo)
Business experience in virtual digital human
嵌入式面试题(算法部分)
Redis
[HDU] 5248 sequence transformation (greedy + dichotomy) [recommended collection]
ip netns 命令(备忘)
Tapdata 的 2.0 版 ,开源的 Live Data Platform 现已发布
AI writes a poem
Micro service remote debug, nocalhost + rainbow micro service development second bullet
Learn open62541 -- [67] add custom enum and display name
我感觉被骗了,微信内测 “大小号” 功能,同一手机号可注册两个微信
编译原理 实验一:词法分析器的自动实现(Lex词法分析)
[Base64 notes] [suggestions collection]
AI写首诗
UVALive – 4621 Cav 贪心 + 分析「建议收藏」
10 schemes to ensure interface data security
PV静态创建和动态创建
Big Ben (Lua)
Longest common prefix (leetcode question 14)
抢占周杰伦