当前位置:网站首页>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)
边栏推荐
- mysql使用笔记一
- LeetCode 1981. Minimize the difference between the target value and the selected element one question per day
- 赋能智慧电力建设 | 麒麟信安高可用集群管理系统,保障用户关键业务连续性
- LeetCode 300. 最长递增子序列 每日一题
- 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?
- Seaborn数据可视化
- Skimage learning (3) -- adapt the gray filter to RGB images, separate colors by immunohistochemical staining, and filter the maximum value of the region
- 自定义View必备知识,Android研发岗必问30+道高级面试题
- MRS离线数据分析:通过Flink作业处理OBS数据
- SlashData开发者工具榜首等你而定!!!
猜你喜欢
Nerf: the ultimate replacement for deepfake?
skimage学习(3)——Gamma 和 log对比度调整、直方图均衡、为灰度图像着色
QT 图片背景色像素处理法
测试用例管理工具推荐
[Seaborn] combination chart: facetgrid, jointgrid, pairgrid
How to add aplayer music player in blog
skimage学习(3)——使灰度滤镜适应 RGB 图像、免疫组化染色分离颜色、过滤区域最大值
《产品经理必读:五种经典的创新思维模型》的读后感
Skimage learning (1)
麒麟信安操作系统衍生产品解决方案 | 存储多路径管理系统,有效提高数据传输可靠性
随机推荐
Matplotlib绘图界面设置
[Fantan] how to design a test platform?
QT中自定义控件的创建到封装到工具栏过程(一):自定义控件的创建
[fan Tan] after the arrival of Web3.0, where should testers go? (ten predictions and suggestions)
DNS series (I): why does the updated DNS record not take effect?
Notes on installing MySQL in centos7
LeetCode 1043. Separate the array to get the maximum and daily questions
[Seaborn] combination chart: facetgrid, jointgrid, pairgrid
LeetCode 1626. 无矛盾的最佳球队 每日一题
服务器彻底坏了,无法修复,如何利用备份无损恢复成虚拟机?
Flask搭建api服务
【视频/音频数据处理】上海道宁为您带来Elecard下载、试用、教程
Skimage learning (3) -- gamma and log contrast adjustment, histogram equalization, coloring gray images
LeetCode 1696. Jumping game VI daily question
【图像传感器】相关双采样CDS
From Devops to mlops: how do it tools evolve to AI tools?
麒麟信安加入宁夏商用密码协会
On Apache Doris Fe processing query SQL source code analysis
LeetCode 1043. 分隔数组以得到最大和 每日一题
[source code interpretation] | source code interpretation of livelistenerbus