asd
🧩 Syntax:
#include<iostream>
using namespace std;
pair<int,int> op(string s){
int a = 10;
int in = -1;
for(int i = 1;i<s.length();i++){
if(a>=3 && s[i] == '/'){
a = 1;
in = i;
}
else if(a>=3 && s[i] == '*'){
a = 2;
in = i;
}
else if(a>=5 && s[i] == '+'){
a = 3;
in = i;
}
else if(a>=5 && s[i] == '-'){
a = 4;
in = i;
}
}
return make_pair(a,in);
}
int main(){
string s;
cin >> s;
while(true){
pair<int,int>p = op(s);
cout << s << "\n";
if(p.second == -1){
break;
}
int j = p.second, k = p.second;
j--; k++;
int x = 1;
while(j>=0 && ((s[j]>='0' && s[j]<='9')||(s[j]=='.'))){
j--;
}
x = 1;
while(k<s.length() && ((s[k]>='0' && s[k]<='9')||(s[k]=='.'))){
k++;
}
float f = 0;
float a = stof(s.substr(j+1,p.second-j));
float b = stof(s.substr(p.second+1, k - p.second));
if(j==0 && s[j]=='-'){
a = -a;
j--;
}
if(p.first == 1){
if(b==0){
cout << "INVALID\n";
return 0;
}
f = a/b;
}
else if(p.first == 2)f = a*b;
else if(p.first == 3)f = a+b;
else if(p.first == 4)f = a-b;
string temp = s;
s = "";
if(j > -1)s+=temp.substr(0,j+1);
s+=to_string(f);
if(k<temp.length())s += temp.substr(k,temp.length()-k);
}
}