当前位置:网站首页>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)
边栏推荐
- 3. About cookies
- Seize Jay Chou
- 咋吃都不胖的朋友,Nature告诉你原因:是基因突变了
- 面试唯品会实习测试岗、抖音实习测试岗【真实投稿】
- How many times is PTA 1101 B than a
- testing and SQA_动态白盒測试[通俗易懂]
- 如何选择合适的自动化测试工具?
- Version 2.0 of tapdata, the open source live data platform, has been released
- 手把手教姐姐写消息队列
- CVPR 2022 - learning non target knowledge for semantic segmentation of small samples
猜你喜欢

Reinforcement learning - learning notes 8 | Q-learning
![Kirk borne's selection of learning resources this week [click the title to download directly]](/img/df/98aa3edf0a70b870684963d52e7c72.png)
Kirk borne's selection of learning resources this week [click the title to download directly]
![[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](/img/08/5f4b4e2700606554516807c01454fd.png)
[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

Creative changes brought about by the yuan universe

Three forms of multimedia technology commonly used in enterprise exhibition hall design

前首富,沉迷种田

Differences between rip and OSPF and configuration commands

Save the memory of the model! Meta & UC Berkeley proposed memvit. The modeling time support is 30 times longer than the existing model, and the calculation amount is only increased by 4.5%

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

Review of network attack and defense
随机推荐
3. About cookies
PTA 1101 B是A的多少倍
2022.07.05
Charles+drony的APP抓包
Nat address translation
App capture of charles+drony
Differences between rip and OSPF and configuration commands
【HDU】5248-序列变换(贪心+二分)「建议收藏」
Sports Federation: resume offline sports events in a safe and orderly manner, and strive to do everything possible for domestic events
Scientists have observed for the first time that the "electron vortex" helps to design more efficient electronic products
LeetCode 890(C#)
AI写首诗
PV静态创建和动态创建
多个kubernetes集群如何实现共享同一个存储
直播预约通道开启!解锁音视频应用快速上线的秘诀
Classification and application of enterprise MES Manufacturing Execution System
"Decryption" Huawei machine vision Corps: Huawei is moving up and the industry is moving forward
How many times is PTA 1101 B than a
SD_ DATA_ RECEIVE_ SHIFT_ REGISTER
Redis cluster and expansion