You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

28 lines
515 B

#include <iostream>
#include <vector>
using namespace std;
int main(){
cout << "请输入一个算式,包含加减乘除乘方括号:" << endl;
string s;
cin >> s;
vector<double> num;
vector<char> symbol;
for (auto x:s){
if((x>47)&&(x<58)){
if(symbol.begin()==symbol.end()){//判断字符栈是否为空
num.push_back(x-'0');
}elif(*(symbol.end()-1)=='46'){
*(num.end()-1)=atof((to_string(*num.end()-1)).c_str()+x);
}
}
}
for (double a:num){
cout << a << endl;
}
return 0;
}