运算2

#include <iostream>
using namespace std;
int main(int argc, char** argv) {
    string n;
    int x=0;
    int n1,n2;
    getline(cin,n);
    if(n.find(" ")>=0&&n.find(" ")<n.size()){
        for(int i=0;i<n.size();i++){
        	for(int j=0;j<n.size();j++){
	        	if(n[i]==' '){
	        		n.erase(i,1);
				}	
			}
        }
    }
    cout<<n<<endl;
    for(int i=0;i<n.size();i++){
    	if(n[i]=='+'||n[i]=='-'||n[i]=='*'||n[i]=='/'){
    		x++;
		}
	} 
	n.insert(0," ");
    for(int i=0;i<n.size()+x*2;i++){
    	if(n[i]=='+'||n[i]=='-'||n[i]=='*'||n[i]=='/'){
    		n.insert(i," ");
    		i+=2;
    		n.insert(i," ");
		}
	}
	n.insert(n.size()," ");
    cout<<n<<"  "<<n.size()<<endl;
    string list[x*2+2];
    
    for(int i=0;i<x*2+2;i++){
    	list[i]=n.substr(n.find(" ",i)+1,n.find(" ",n.find(" ",i)+1)-1);
	}
    cout<<list[1]<<" "<<list[1].size()<<endl;
//    if(n.find("*")>0&&n.find("*")<n.size()||n.find("/")>0&&n.find("/")<n.size()){
//    	for(int i=0;i<n.size();i++){
//    		if(n[i]=='*'){
//    			
//			}
//    		
//		}
//    	
//        n1=stoi(n.substr(0,n.find("*")));
//        n2=stoi(n.substr(n.find("*")+1,n.size()-n.find("*")));
//        cout<<n1*n2;
//        
//    }
//    
//	else if(n.find("+")>0&&n.find("+")<n.size()){
//        n1=stoi(n.substr(0,n.find("+")));
//        n2=stoi(n.substr(n.find("+")+1,n.size()-n.find("+")));
//        cout<<n1+n2;
//    }
//    else if(n.find("-")>0&&n.find("-")<n.size()){
//        n1=stoi(n.substr(0,n.find("-")));
//        n2=stoi(n.substr(n.find("-")+1,n.size()-n.find("-")));
//        cout<<n1-n2;
//    }

    return 0;
}

  

posted @ 2023-11-12 09:40  王ys  阅读(4)  评论(0编辑  收藏  举报