四则运算

#include <bits/stdc++.h>
#include <string>
#include <iomanip>
using namespace std;
int kongge(string a);
int jia(string a);
int jian(string a);
int chu(string a);
int cheng(string a);
int main(int argc, char** argv) {
string str;
getline(cin,str);
if(str.find("+")>0 && str.find("+")<str.size()){
cout<<jia(str);
}else if(str.find("-")>0 && str.find("-")<str.size()){
cout<<jian(str);
}else if(str.find("*")>0 && str.find("*")<str.size()){
cout<<cheng(str);
}else if(str.find("/")>0 && str.find("/")<str.size()){
cout<<chu(str);
}
return 0;
}
int cheng(string str){
int no1=kongge(str.substr(0,str.find("*")));
int no2=kongge(str.substr(str.find("*")+1,str.length()-str.find("*")));
return no1*no2;
}
int chu(string str){
int no1=kongge(str.substr(0,str.find("/")));
int no2=kongge(str.substr(str.find("/")+1,str.length()-str.find("/")));
return no1/no2;
}
int jian(string str){
int no1=kongge(str.substr(0,str.find("-")));
int no2=kongge(str.substr(str.find("-")+1,str.length()-str.find("-")));
return no1-no2;
}
int kongge(string a){
while(a.find(" ")>=0 && a.find(" ")<=a.length()){
a.replace(a.find(" "),1,"");
}
int no1=stoi(a);
return no1;
}
int jia(string str){
int no1=kongge(str.substr(0,str.find("+")));
int no2=kongge(str.substr(str.find("+")+1,str.length()-str.find("+")));
return no1+no2;
}
int hui(string str){

return 0;
}

posted @ 2023-11-12 08:46  最后一个还有我  阅读(19)  评论(0)    收藏  举报