#include <bits/stdc++.h> using namespace std; int js(string a,string b);//计算 //int jianfa(string a); //int chengfa(string a); //int chufa(string a); string no1(string x);//清除空格 int main(){ string a; getline(cin,a); a=no1(a); if(a.find("+")>0 && a.find("+")<a.size()){ cout<<js(a,"+"); }else if(a.find("-")>0 && a.find("-")<a.size()){ cout<<js(a,"-"); }else if(a.find("*")>0 && a.find("*")<a.size()){ cout<<js(a,"*"); }else if(a.find("/")>0 && a.find("/")<a.size()){ cout<<js(a,"/"); } return 0; } string no1(string a){ while(a.find(" ")>=0 && a.find(" ")<a.size()){ a.replace(a.find(" "),1,""); } return a; } int js(string a,string b){ int x = stoi(a.substr(0,a.find(b))); int y = stoi(a.substr(a.find(b)+1)); if(b=="+"){ return x+y; }if(b=="-"){ return x-y; }if(b=="*"){ return x*y; }if(b=="/"){ return x/y; } }
标签:string,int,四则运算,find,&&,no1 From: https://www.cnblogs.com/fushuxuan/p/17826773.html