当前位置:网站首页>L1-025 正整数A+B (15 分)
L1-025 正整数A+B (15 分)
2022-04-22 17:35:00 【wow_awsl_qwq】
题的目标很简单,就是求两个正整数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:
? + ? = ?
坑点:题目中说:其中A和B都在区间[1,1000]。以为是数据的保证,而不是需要自己判断。又是谜语人的一天呢
#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
const int N=100005;
int j,o;
int toi(string s)
{
int n=s.size();
int res=0;
for(int i=0;i<n;++i)
{
res*=10;
res+=s[i]-'0';
}
return res;
}
bool ck(string s)
{
for(int i=0;i<s.size();++i)
{
if(!isdigit(s[i]))return false;
}
if(toi(s)>1000||toi(s)<1)return false;
return true;
}
int main()
{
ios::sync_with_stdio(false);
string a,b,p;
getline(cin,p);
int t=p.find(" ");
a=p.substr(0,t);
b=p.substr(t+1);
if(ck(a)&&ck(b)){
int x=toi(a);
int y=toi(b);
cout<<x<<" + "<<y<<" = "<<x+y;
}
else {
if(ck(a))cout<<toi(a);
else cout<<"?";
cout<<" + ";
if(ck(b))cout<<toi(b);
else cout<<"?";
cout<<" = ?";
}
return 0;
}
版权声明
本文为[wow_awsl_qwq]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_42641977/article/details/124339383
边栏推荐
- How does PR modify the name of the program and how does PR modify the name of the sequence
- [golang] force buckle leetcode - 657 Whether the robot can return to the origin (simulation)
- S7-1500 CPU通过OPC UA客户端与OPC UA服务器进行数据交换的具体方法步骤
- CISP-PTE SQL注入 进阶篇之实战模拟
- Opendaylight analysis of SDN learning (1)
- 丘成桐已全职加入清华
- 小程序如何集成即構IM實現即時通訊發消息聊天
- 禁止复制网页中的内容
- 这或许是最详细的机器学习模型融合大法汇总
- 京东一面:子线程如何获取父线程 ThreadLocal 的值?我蒙了。。。
猜你喜欢

Redis(16) -- Redis集群

Notes on deep learning (I) -- loss function

Use (add) virtual environment in Jupiter notebook

How can Hong Kong cloud servers avoid blackmail software attacks?

Ifconfig, route, IP route, IP addr, IP link usage

March 2022 - true questions and analysis of C language (Level 2) in the youth grade examination of the Electronic Society

丘成桐已全职加入清华

Typical application scenarios of alicloud log service SLS

如何快速接入直播服务 七牛云企业直播解决方案来了

How to complete code merging through cloud effect codeup | cloud effect
随机推荐
400 million women just need, all kinds of capital kill: 100 billion business hidden in sanitary napkins
7. 堪比JMeter的.Net压测工具 - Crank 总结篇 - crank带来了什么
非线性优化问题---MATLAB
How does the applet integrate instant messaging with instant messaging
關於閉包的7道面試題
Regular matching URL
Opendaylight analysis of SDN learning (5)
香港云服务器怎样避免勒索软件攻击?
Go 学习笔记——Switch(我不是游戏机)
VSCODE + PHP Debug + 名字空间指引
About wechat applet, solve the problem of blank area caused by keyboard bounce when there is tabbar
PHP AES加密解密
Facing the global market, platefarm today logs in to four major global platforms such as Huobi
JS实现常见的六大排序
知乎在港上市破发是必然:周源被“打脸”,增长极其依赖营销
发起成立波场联合储备,孙宇晨向美联储发起“挑战”
7 Questions d'entrevue sur la fermeture
用户画像之线性回归逻辑回归综合实战
Anomaly detection of log sequence based on depth model
It's not just what you see on the surface, but the product logic behind JetBlue Dasheng