#include <bits/stdc++.h> using namespace std; string kong(string a){ while(a.find(" ")>=0&&a.find(" ")<=a.size()){ a.replace(a.find(" "),1,""); } return a; } int b(string a,string b){ int c=stoi(a.substr(0,a.find(b))); int d=stoi(a.substr(a.find(b)+1)); if(b=="+"){ return c+d; }else if(b=="-"){ return c-d; }else if(b=="*"){ return c*d; }else if(b=="/"){ return c/d; } } int main(){ string a; getline(cin,a); a=kong(a); if(a.find("*")>0&&a.find("*")<a.size()){ while(a.find("*")>0&&a.find("*")<a.size()){ a=to_string(b(a,"*"))+a.substr(a.find("*")+2); } }else if(a.find("/")>0&&a.find("/")<a.size()){ while(a.find("/")>0&&a.find("/")<a.size()){ a=to_string(b(a,"/"))+a.substr(a.find("/")+2); } }else if(a.find("+")>0&&a.find("+")<a.size()){ while(a.find("+")>0&&a.find("+")<a.size()){ a=to_string(b(a,"+"))+a.substr(a.find("+")+2); } }else if(a.find("-")>0&&a.find("-")<a.size()){ while(a.find("-")>0&&a.find("-")<a.size()){ a=to_string(b(a,"-"))+a.substr(a.find("-")+2); } } cout<<a; }
标签:don,string,四则运算,完整,&&,find From: https://www.cnblogs.com/As10016/p/17826764.html