当前位置:网站首页>L1-027 出租(Lua)
L1-027 出租(Lua)
2022-07-07 15:38:00 【有趣就行】
题目
一时间网上一片求救声,急问这个怎么破。其实这段代码很简单,index数组就是arr数组的下标,index[0]=2 对应 arr[2]=1,index[1]=0 对应 arr[0]=8,index[2]=3 对应 arr[3]=0,以此类推…… 很容易得到电话号码是18013820100。
本题要求你编写一个程序,为任何一个电话号码生成这段代码 —— 事实上,只要生成最前面两行就可以了,后面内容是不变的。
输入格式:
输入在一行中给出一个由11位数字组成的手机号码。
输出格式:
为输入的号码生成代码的前两行,其中arr中的数字必须按递减顺序给出。
输入样例:
18013820100
输出样例:
int[] arr = new int[]{8,3,2,1,0};
int[] index = new int[]{3,0,4,3,1,0,2,4,3,4,4};
代码
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)
边栏推荐
- The computer cannot add a domain, and the Ping domain name is displayed as the public IP. What is the problem? How to solve it?
- LeetCode 1477. Find two subarrays with sum as the target value and no overlap
- Matplotlib绘制三维图形
- First in China! Todesk integrates RTC technology into remote desktop, with clearer image quality and smoother operation
- 麒麟信安中标国网新一代调度项目!
- Sator推出Web3遊戲“Satorspace” ,並上線Huobi
- 如何在软件研发阶段落地安全实践
- QT 图片背景色像素处理法
- Solidity 开发环境搭建
- Shallow understanding Net core routing
猜你喜欢
How to choose the appropriate automated testing tools?
PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
专精特新软件开发类企业实力指数发布,麒麟信安荣誉登榜
赋能智慧电力建设 | 麒麟信安高可用集群管理系统,保障用户关键业务连续性
Direct dry goods, 100% praise
Sator a lancé le jeu web 3 "satorspace" et a lancé huobi
QML初学
NeRF:DeepFake的最终替代者?
SlashData开发者工具榜首等你而定!!!
SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名
随机推荐
What is cloud computing?
Sator推出Web3游戏“Satorspace” ,并上线Huobi
LeetCode 1626. The best team without contradiction
The process of creating custom controls in QT to encapsulating them into toolbars (II): encapsulating custom controls into toolbars
【源码解读】| LiveListenerBus源码解读
[Seaborn] combination chart: facetgrid, jointgrid, pairgrid
LeetCode 1155. N ways to roll dice one question per day
Rpcms method of obtaining articles under the specified classification
Read PG in data warehouse in one article_ stat
LeetCode 312. 戳气球 每日一题
LeetCode 300. Daily question of the longest increasing subsequence
MRS离线数据分析:通过Flink作业处理OBS数据
[Fantan] how to design a test platform?
管理VDI的几个最佳实践
【Seaborn】组合图表、多子图的实现
Notes on installing MySQL in centos7
The server is completely broken and cannot be repaired. How to use backup to restore it into a virtual machine without damage?
LeetCode 1626. 无矛盾的最佳球队 每日一题
Seaborn data visualization
LeetCode 1049. 最后一块石头的重量 II 每日一题