当前位置:网站首页>Niuke network realizes simple calculator function
Niuke network realizes simple calculator function
2022-06-24 09:16:00 【SZU healing system bug】
Catalog
Title Description
Enter a string on the keyboard , Format : How it works Integers 1 Integers 2, Write a program to parse the... In the string 3 Part content , Then do the corresponding operation , And output the result .
for example :
Input “add 10 20”, Then add (10+20);
Input “sub 10 20”, Then subtract (10-20);
Input “mul 10 20”, Then do multiplication (10*20);
Input “div 10 20”, Then do the division operation (10/20), If the divisor is 0, Then do no operation , Output “Error”;
Be careful : Operation mode ignores case , namely “add” Same as “Add”、“ADD” etc. .
Input description :
Enter a string on the keyboard , Format : How it works Integers 1 Integers 2
The integer range is [-100, 100]
Output description :
Output the result of the operation ( Division does not take into account decimals ), If the divisor is 0, Then do no operation , Output “Error”
Example 1
Input :
add 10 3
Copy output :
13
Copy
Example 2
Input :
sub 10 3
Copy output :
7
Copy
Example 3
Input :
mul 10 3
Copy output :
30
Copy
Example 4
Input :
div 10 3
Copy output :
3
Copy
Example 5
Input :
div 10 0
Copy output :
Error
Copy
Example 6
Input :
ADD 20 20
Copy output :
40
AC Code
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
string code;
int a, b;
cin >> code >> a >> b;
transform(code.begin(), code.end(), code.begin(), ::toupper);
if (code == "ADD")
cout << a + b;
else if (code == "SUB")
cout << a - b;
else if (code == "MUL")
cout << a*b;
else {
if (b)
cout << a / b;
else
cout << "Error";
}
}边栏推荐
- MySQL | store notes of Master Kong MySQL from introduction to advanced
- 怎么把mdf和ldf文件导入MySQL workbench中
- Remote connection of raspberry pie without display by VNC viewer
- P6698-[BalticOI 2020 Day2]病毒【AC自动机,dp,SPFA】
- 【LeetCode】415. String addition
- Webrtc series - network transmission 5: select the optimal connection switching
- Zero foundation self-study SQL course | syntax sequence and execution sequence of SQL statements
- 4274. suffix expression
- When programmers are asked if they can repair computers... | daily anecdotes
- Scheme of alcohol concentration tester based on single chip microcomputer
猜你喜欢

普通人没有学历,自学编程可以月入过万吗?

linux(centos7.9)安装部署mysql-cluster 7.6

零基础自学SQL课程 | HAVING子句

MySQL | store notes of Master Kong MySQL from introduction to advanced

Qingcloud based "real estate integration" cloud solution

【LeetCode】387. First unique character in string

Data midrange: detailed explanation of the technical stack of data acquisition and extraction

CF566E-Restoring Map【bitset】

Groovy通过withCredentials获取Jenkins凭据

活动报名|Apache Pulsar x KubeSphere 在线 Meetup 火热报名中
随机推荐
十二、所有功能实现效果演示
Threejs glow channel 01 (unrealbroompass & layers)
Opencv daily function structure analysis and shape descriptor (7) finding polygon (contour) / rotating rectangle intersection
Leetcode -- wrong set
[redis implements seckill business ①] seckill process overview | basic business implementation
Groovy通过withCredentials获取Jenkins凭据
Weekly recommended short video: talk about "meta universe" with a serious attitude
12、 Demonstration of all function realization effects
Code written by mysql, data addition, deletion, query and modification, etc
520. detect capital letters
深入了解 border
Every (), map (), forearch () methods. There are objects in the array
Zero foundation self-study SQL course | syntax sequence and execution sequence of SQL statements
Data midrange: detailed explanation of the technical stack of data acquisition and extraction
Yolox backbone -- implementation of cspparknet
牛客网 十进制整数转十六进制字符串
[quantitative investment] discrete Fourier transform to calculate array period
YOLOX backbone——CSPDarknet的实现
Rpiplay implementation of raspberry pie airplay projector
Target detection series fast r-cnn