当前位置:网站首页>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)
边栏推荐
猜你喜欢

Nerf: the ultimate replacement for deepfake?

skimage学习(2)——RGB转灰度、RGB 转 HSV、直方图匹配

Module VI

skimage学习(3)——Gamma 和 log对比度调整、直方图均衡、为灰度图像着色

Sator推出Web3游戏“Satorspace” ,并上线Huobi

Lowcode: four ways to help transportation companies enhance supply chain management

What is cloud computing?

测试用例管理工具推荐

QT中自定义控件的创建到封装到工具栏过程(一):自定义控件的创建

Sator推出Web3遊戲“Satorspace” ,並上線Huobi
随机推荐
NeRF:DeepFake的最终替代者?
Flask搭建api服务-SQL配置文件
科普达人丨一文弄懂什么是云计算?
LeetCode 403. Frog crossing the river daily
Sator推出Web3游戏“Satorspace” ,并上线Huobi
MRS离线数据分析:通过Flink作业处理OBS数据
自定义View必备知识,Android研发岗必问30+道高级面试题
SlashData开发者工具榜首等你而定!!!
Sator推出Web3游戏“Satorspace” ,并上线Huobi
DNS series (I): why does the updated DNS record not take effect?
Reflections on "product managers must read: five classic innovative thinking models"
LeetCode 1626. 无矛盾的最佳球队 每日一题
智慧物流平台:让海外仓更聪明
Lowcode: four ways to help transportation companies enhance supply chain management
Rpcms method of obtaining articles under the specified classification
麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会
LeetCode 1654. 到家的最少跳跃次数 每日一题
dapp丨defi丨nft丨lp单双币流动性挖矿系统开发详细说明及源码
QT中自定义控件的创建到封装到工具栏过程(一):自定义控件的创建
【Seaborn】组合图表:PairPlot和JointPlot