-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathccong.c
46 lines (45 loc) · 817 Bytes
/
ccong.c
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
#include<stdio.h>
void push(char);
char pop();
char str[405],st[405];
int t,top,i;
int main()
{
char ch;
scanf("%d",&t);
while(t--)
{
top=-1;
scanf("%s",str);
for(i=0;str[i]!='\0';i++)
{
if(str[i]=='(' || str[i]=='*' || str[i]=='+' || str[i]=='/' || str[i]=='-'|| str[i]=='^')
push(str[i]);
else if(str[i]==')')
{
ch=pop();
while(ch!='(')
{
printf("%c",ch);
ch=pop();
}
}
else
printf("%c",str[i]);
}
printf("\n");
}
return 0;
}
void push(char ch)
{
top++;
st[top]=ch;
}
char pop()
{
char ch;
ch=st[top];
top--;
return ch;
}