-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathONP.cpp
59 lines (54 loc) · 917 Bytes
/
ONP.cpp
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
59
#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
void parse(char array[], int size)
{
int i=0,stkptr=0;
char stack[size];
while(array[i]!=0)
{
switch(array[i])
{
case '(': break;
case '+': stack[stkptr]='+';
stkptr++;
break;
case '-': stack[stkptr]='-';
stkptr++;
break;
case '*': stack[stkptr]='*';
stkptr++;
break;
case '/': stack[stkptr]='/';
stkptr++;
break;
case '^': stack[stkptr]='^';
stkptr++;
break;
case ')': cout<<stack[--stkptr];
break;
default : cout<<array[i];
break;
}
i++;
}
cout<<"\n";
return;
}
int main()
{
std::ios::sync_with_stdio(false);
int n,i=0;
string str;
cin>>n;
while(n--)
{
cin>>str;
char array[str.length()];
std::strncpy(array,str.c_str(),sizeof(array));
array[sizeof(array)]=0;
parse(array,str.length());
}
return 0;
}