#include <bits/stdc++.h> using namespace std; int js(string a,string b); 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/wangyanbo111/p/17839563.html