当前位置:网站首页>L1-025 positive integer a+b (15 points)
L1-025 positive integer a+b (15 points)
2022-07-04 07:29:00 【Inter personal liabilities^】
L1-025 Positive integer A+B (15 branch )
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 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:
? + ? = ?
test 3: Similar to the third example , There may be more than two data entered , When the input data exceeds two data , You should directly output the results that are all question marks
test 5: The upper limit of the number is 1000, There are requirements for the topic , But when typing , I didn't input as required, so I need to judge
test 6: The lower limit of the number is 1, And testing 5 identical
AC Code
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<sstream>
using namespace std;
typedef long long ll;
const int N=100010;
int main()
{
string a;
getline(cin, a);
bool flaga = false, flagb = false;
int aa = 0, bb = 0;
int flag = 0;
for(int i = 0; i < a.size(); i ++ )
{
if(a[i] == ' ') flag = i;
if(flag > 0) break;
}
for(int i = 0; i < flag; i ++ )
{
aa = aa * 10 + (a[i] - '0');
if(a[i] < '0' || a[i] > '9')
{
flaga = true;
break;
}
}
int flag1 = 0;
for(int i = flag + 1; i < a.size(); i ++ )
{
bb = bb * 10 + (a[i] - '0');
if(a[i] < '0' || a[i] > '9')
{
flagb = true;
break;
}
}
if(aa > 1000 || aa < 1) flaga = true;
if(bb > 1000 || bb < 1) flagb = true;
if(flaga) cout << '?' << ' ';
else cout << aa << ' ';
cout << '+' << ' ';
if(flagb) cout << '?' << ' ';
else cout << bb << ' ';
cout << '=' << ' ';
if(flaga || flagb) cout << '?';
else cout << aa + bb;
return 0;
}
边栏推荐
- Data double write consistency between redis and MySQL
- Boosting the Performance of Video Compression Artifact Reduction with Reference Frame Proposals and
- Amd RX 7000 Series graphics card product line exposure: two generations of core and process mix and match
- [FreeRTOS] FreeRTOS learning notes (7) - handwritten FreeRTOS two-way linked list / source code analysis
- Oceanbase is the leader in the magic quadrant of China's database in 2021
- 大学阶段总结
- Zephyr learning notes 1, threads
- Redis - detailed explanation of cache avalanche, cache penetration and cache breakdown
- Zephyr Learning note 2, Scheduling
- com. alibaba. nacos. api. exception. NacosException
猜你喜欢

Unity opens the explorer from the inspector interface, selects and records the file path

Set JTAG fuc invalid to normal IO port

Node connection MySQL access denied for user 'root' @ 'localhost' (using password: yes

Computer connects raspberry pie remotely through putty

Review of enterprise security incidents: how can enterprises do a good job in preventing source code leakage?

Distributed transaction management DTM: the little helper behind "buy buy buy"

Su Weijie, a member of Qingyuan Association and an assistant professor at the University of Pennsylvania, won the first Siam Youth Award for data science, focusing on privacy data protection, etc
![[C language] open the door of C](/img/e0/2f107966423d6492c39995c77a445e.jpg)
[C language] open the door of C
![[MySQL transaction]](/img/4f/dbfa1bf999cfcbbe8f3b27bb1e932b.jpg)
[MySQL transaction]

Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
随机推荐
Introduction to deep learning Ann neural network parameter optimization problem (SGD, momentum, adagrad, rmsprop, Adam)
[thread pool]
【FreeRTOS】FreeRTOS學習筆記(7)— 手寫FreeRTOS雙向鏈錶/源碼分析
Set JTAG fuc invalid to normal IO port
Electronic Association C language level 1 35, bank interest
Boosting the Performance of Video Compression Artifact Reduction with Reference Frame Proposals and
MySQL中的文本處理函數整理,收藏速查
The frost peel off the purple dragon scale, and the xiariba people will talk about database SQL optimization and the principle of indexing (primary / secondary / clustered / non clustered)
Comparison between applet framework and platform compilation
Introduction to rce in attack and defense world
Advanced MySQL: Basics (5-8 Lectures)
大学阶段总结
Knowledge payment applet dream vending machine V2
Zephyr learning notes 1, threads
Rhcsa day 3
MySQL 数据库 - 函数 约束 多表查询 事务
Amd RX 7000 Series graphics card product line exposure: two generations of core and process mix and match
Review of enterprise security incidents: how can enterprises do a good job in preventing source code leakage?
What are the work contents of operation and maintenance engineers? Can you list it in detail?
Data double write consistency between redis and MySQL