-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp1.cpp
More file actions
58 lines (57 loc) · 1.27 KB
/
p1.cpp
File metadata and controls
58 lines (57 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
int i;
string in, temp = "";
vector<string> term;
vector<char> op;
getline(cin, in);
for(auto it = in.begin(); it != in.end(); it++){
if(*it == ' '){
in.erase(it);
it--;
}
}
for(auto it = in.begin(); it != in.end(); it++){
switch(*it){
case '+':
case '-':
case '/':
case '*':
case '=':
if(temp!="")
term.push_back(temp);
temp = "";
op.push_back(*it);
break;
default:
temp += *it;
}
}
if(temp != "")
term.push_back(temp);
i = 0;
for(int it = 0; it != op.size(); it++){
if(op[it] == '/' || op[it] == '*'){
cout << 't' << i << " = " << term[it] << ' ' << op[it] << ' ' << term[it+1] << endl;
op.erase(op.begin() + it);
term.erase(term.begin() + it);
term[it] = "t" + to_string(i);
it--;
i++;
}
}
for(int it = 1; it != op.size(); it++){
if(op[it] != '='){
cout << 't' << i << " = " << term[it] << ' ' << op[it] << ' ' << term[it+1] << endl;
op.erase(op.begin() + it);
term.erase(term.begin() + it);
term[it] = "t" + to_string(i);
it--;
i++;
}
}
cout << term[0] << " = " << term[1] << endl;
}