当前位置:网站首页>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)
边栏推荐
- 2022-07-04 matlab reads video frames and saves them
- [information security laws and regulations] review
- Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind
- 初识缓存以及ehcache初体验「建议收藏」
- Thread factory in thread pool
- RISCV64
- 杰理之按键发起配对【篇】
- 我感觉被骗了,微信内测 “大小号” 功能,同一手机号可注册两个微信
- 解决远程rviz报错问题
- 编译原理 实验一:词法分析器的自动实现(Lex词法分析)
猜你喜欢

The top of slashdata developer tool is up to you!!!

Do you know all four common cache modes?

编译原理 实验一:词法分析器的自动实现(Lex词法分析)

In 2021, the national average salary was released. Have you reached the standard?

Chief technology officer of Pasqual: analog quantum computing takes the lead in bringing quantum advantages to industry

Basic operation of chain binary tree (implemented in C language)

SD_ DATA_ RECEIVE_ SHIFT_ REGISTER

50亿,福建又诞生一只母基金

App capture of charles+postern

Pasqal首席技术官:模拟量子计算率先为工业带来量子优势
随机推荐
Version 2.0 of tapdata, the open source live data platform, has been released
I feel cheated. Wechat tests the function of "size number" internally, and two wechat can be registered with the same mobile number
RISCV64
Solve the error reporting problem of rosdep
[mime notes]
杰理之手动配对方式【篇】
Creative changes brought about by the yuan universe
How many are there (Lua)
Where does brain hole come from? New research from the University of California: creative people's neural connections will "take shortcuts"
PV静态创建和动态创建
L1-028 judging prime number (Lua)
Responsibility chain model - unity
脑洞从何而来?加州大学最新研究:有创造力的人神经连接会「抄近道」
Review of network attack and defense
编译原理 实验一:词法分析器的自动实现(Lex词法分析)
Draw squares with Obama (Lua)
企业MES制造执行系统的分类与应用
2022.07.02
网易云信参与中国信通院《实时音视频服务(RTC)基础能力要求及评估方法》标准编制...
Complete e-commerce system