当前位置:网站首页>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实现两个字段合并成一个字段查询
- QT 图片背景色像素处理法
- Localstorage and sessionstorage
- 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?
- NeRF:DeepFake的最终替代者?
- LeetCode 1654. The minimum number of jumps to get home one question per day
- 麒麟信安加入宁夏商用密码协会
- Matplotlib绘制三维图形
- Direct dry goods, 100% praise
- LeetCode 1031. Maximum sum of two non overlapping subarrays
猜你喜欢

管理VDI的几个最佳实践

麒麟信安操作系统衍生产品解决方案 | 存储多路径管理系统,有效提高数据传输可靠性

Process from creation to encapsulation of custom controls in QT to toolbar (I): creation of custom controls

skimage学习(1)

Skimage learning (2) -- RGB to grayscale, RGB to HSV, histogram matching

Pychart ide Download

Nerf: the ultimate replacement for deepfake?
![[video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial](/img/14/4e7ebfb1ed5b99f8377af9d17d2177.jpg)
[video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial
直接上干货,100%好评
![[image sensor] correlated double sampling CDs](/img/1c/3a641ad47ff91536db602dedc82705.png)
[image sensor] correlated double sampling CDs
随机推荐
LeetCode 1043. 分隔数组以得到最大和 每日一题
99% 用户在 Power BI 云端报表常犯错误
LeetCode 300. Daily question of the longest increasing subsequence
LeetCode 213. Home raiding II daily question
Biped robot controlled by Arduino
LeetCode 1477. Find two subarrays with sum as the target value and no overlap
Linux 安装mysql8.X超详细图文教程
如何在博客中添加Aplayer音乐播放器
Seaborn数据可视化
DNS 系列(一):为什么更新了 DNS 记录不生效?
mysql使用笔记一
防火墙系统崩溃、文件丢失的修复方法,材料成本0元
LeetCode 403. Frog crossing the river daily
LeetCode 1626. 无矛盾的最佳球队 每日一题
Mrs offline data analysis: process OBS data through Flink job
centos7安装mysql笔记
SlashData开发者工具榜首等你而定!!!
【Seaborn】组合图表:FacetGrid、JointGrid、PairGrid
【饭谈】如何设计好一款测试平台?
Flask搭建api服务