当前位置:网站首页>L1-025 正整数A+B(Lua)
L1-025 正整数A+B(Lua)
2022-07-07 15:38:00 【有趣就行】
题目
题的目标很简单,就是求两个正整数A和B的和,其中A和B都在区间[1,1000]。稍微有点麻烦的是,输入并不保证是两个正整数。
输入格式:
输入在一行给出A和B,其间以空格分开。问题是A和B不一定是满足要求的正整数,有时候可能是超出范围的数字、负数、带小数点的实数、甚至是一堆乱码。
注意:我们把输入中出现的第1个空格认为是A和B的分隔。题目保证至少存在一个空格,并且B不是一个空字符串。
输出格式:
如果输入的确是两个正整数,则按格式A + B = 和输出。如果某个输入不合要求,则在相应位置输出?,显然此时和也是?。
输入样例1:
123 456
输出样例1:
123 + 456 = 579
输入样例2:
22. 18
输出样例2:
? + 18 = ?
输入样例3:
-100 blabla bla…33
输出样例3:
? + ? = ?
代码
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)
边栏推荐
- [Seaborn] implementation of combined charts and multi subgraphs
- LeetCode 1696. 跳跃游戏 VI 每日一题
- skimage学习(1)
- Notes on installing MySQL in centos7
- LeetCode 1774. The dessert cost closest to the target price is one question per day
- 麒麟信安云平台全新升级!
- First in China! Todesk integrates RTC technology into remote desktop, with clearer image quality and smoother operation
- LeetCode 1031. 两个非重叠子数组的最大和 每日一题
- QT中自定义控件的创建到封装到工具栏过程(一):自定义控件的创建
- Share the latest high-frequency Android interview questions, and take you to explore the Android event distribution mechanism
猜你喜欢
【图像传感器】相关双采样CDS
Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind
Sator a lancé le jeu web 3 "satorspace" et a lancé huobi
Sator推出Web3游戏“Satorspace” ,并上线Huobi
SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名
Mrs offline data analysis: process OBS data through Flink job
Skimage learning (1)
Seaborn数据可视化
Skimage learning (3) -- adapt the gray filter to RGB images, separate colors by immunohistochemical staining, and filter the maximum value of the region
AI来搞财富分配比人更公平?来自DeepMind的多人博弈游戏研究
随机推荐
Direct dry goods, 100% praise
Flash build API service
LeetCode 1043. Separate the array to get the maximum and daily questions
如何在博客中添加Aplayer音乐播放器
【Seaborn】组合图表:FacetGrid、JointGrid、PairGrid
LeetCode 1155. N ways to roll dice one question per day
QT中自定义控件的创建到封装到工具栏过程(二):自定义控件封装到工具栏
邮件服务器被列入黑名单,如何快速解封?
Seaborn data visualization
From Devops to mlops: how do it tools evolve to AI tools?
麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会
PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
Pychart ide Download
QT视频传输
LeetCode 213. 打家劫舍 II 每日一题
LeetCode 1626. The best team without contradiction
Process from creation to encapsulation of custom controls in QT to toolbar (I): creation of custom controls
The mail server is listed in the blacklist. How to unblock it quickly?
LeetCode 1981. Minimize the difference between the target value and the selected element one question per day
Proxmox VE重装后,如何无损挂载原有的数据盘?