当前位置:网站首页>L1-025 positive integer a+b (Lua)
L1-025 positive integer a+b (Lua)
2022-07-07 19:14:00 【Just be interesting】
subject
The goal of the question is very simple , It's two positive integers A and B And , among A and B It's all in the range [1,1000]. A little bit of a hassle , The input is not guaranteed to be two positive integers .
Input format :
Type in on a line to give A and B, They are separated by spaces . The problem is A and B It doesn't have to be a positive integer , Sometimes it can be out of range numbers 、 negative 、 A real number with a decimal point 、 It's even a mess of code .
Be careful : Let's put... In the input 1 A space is taken as A and B Separation of . Make sure that there is at least one space for the question , also B It's not an empty string .
Output format :
If the input is really two positive integers , According to the format A + B = And the output . If an input is not satisfactory , Output at corresponding position ?, Obviously at this time and also ?.
sample input 1:
123 456
sample output 1:
123 + 456 = 579
sample input 2:
22. 18
sample output 2:
? + 18 = ?
sample input 3:
-100 blabla bla…33
sample output 3:
? + ? = ?
Code
function io.read2value()
local s = io.read()
local n = #s
for i = 1, n do
if s:sub(i, i) == " " then
return s:sub(1, i - 1), s:sub(i + 1)
end
end
end
local s1, s2 = io.read2value()
local flag1, flag2 = true, true
if tostring(tonumber(s1)) ~= s1 or s1:find(".", 1, true) ~= nil then
flag1 = false
end
if tostring(tonumber(s2)) ~= s2 or s2:find(".", 1, true) ~= nil then
flag2 = false
end
local s = ""
local n1, n2 = tonumber(s1), tonumber(s2)
if n1 and (n1 <= 0 or n1 > 1000) then flag1 = false end
if n2 and (n2 <= 0 or n2 > 1000) then flag2 = false end
s = s .. (flag1 and n1 or "?")
s = s .. " + "
s = s .. (flag2 and n2 or "?")
s = s .. " = "
s = s .. ((flag1 and flag2) and (n1 + n2) or "?")
print(s)
边栏推荐
- Continuous test (CT) practical experience sharing
- DeSci:去中心化科学是Web3.0的新趋势?
- ES6 note 1
- Learn open62541 -- [67] add custom enum and display name
- 从39个kaggle竞赛中总结出来的图像分割的Tips和Tricks
- 6.关于jwt
- 3.关于cookie
- Uvalive – 4621 CAV greed + analysis "suggestions collection"
- 基于图像和激光的多模态点云融合与视觉定位
- 【软件测试】从企业版BOSS直聘,看求职简历,你没被面上是有原因的
猜你喜欢
In the first half of 2022, I found 10 books that have been passed around by my circle of friends
伺服力矩控制模式下的力矩目标值(fTorque)计算
Seize Jay Chou
5billion, another master fund was born in Fujian
App capture of charles+drony
How to estimate the value of "not selling pens" Chenguang?
Pasqal首席技术官:模拟量子计算率先为工业带来量子优势
Calculation of torque target value (ftorque) in servo torque control mode
Realize payment function in applet
[tpm2.0 principle and Application guide] Chapter 16, 17 and 18
随机推荐
抢占周杰伦
SlashData开发者工具榜首等你而定!!!
Redis的发布与订阅
[Blue Bridge Cup training 100 questions] sort scratch from small to large. Blue Bridge Cup scratch competition special prediction programming question centralized training simulation exercise question
testing and SQA_动态白盒測试[通俗易懂]
PTA 1102 teaching Super Champion volume
嵌入式面试题(算法部分)
Redis
Business experience in virtual digital human
Short selling, overprinting and stock keeping, Oriental selection actually sold 2.66 million books in Tiktok in one month
Differences between rip and OSPF and configuration commands
Draw squares with Obama (Lua)
Simple configuration of single arm routing and layer 3 switching
链式二叉树的基本操作(C语言实现)
"Decryption" Huawei machine vision Corps: Huawei is moving up and the industry is moving forward
Learn open62541 -- [67] add custom enum and display name
Interview vipshop internship testing post, Tiktok internship testing post [true submission]
2022.07.05
POJ 2392 Space Elevator
Charles+drony的APP抓包