http://acm.nyist.net/JudgeOnline/problem.php?pid=257
栈的应用....
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include <stdio.h> 2 #include <string.h> 3 #define maxn 1005 4 char stack[maxn],str[maxn],source[maxn]; 5 int main() 6 { 7 int i,j,l,k,t,le,rear; 8 scanf("%d",&t); 9 while(t--) 10 { 11 scanf("%s",str); 12 le=strlen(str); 13 rear=-1; 14 l=0; 15 for(i=0;i<le;i++) 16 { 17 if(str[i]==')') 18 { 19 while(stack[rear]!='(') 20 { 21 source[l]=stack[rear]; 22 l++; 23 rear--; 24 } 25 rear--; 26 } 27 else if('0'<=str[i] && str[i]<='9') 28 { 29 source[l]=str[i]; 30 l++; 31 } 32 else if(str[i]=='(') 33 { 34 stack[++rear]=str[i]; 35 } 36 else if(str[i]=='/' || str[i]=='*') 37 { 38 while(stack[rear]=='/' || stack[rear]=='*') 39 { 40 source[l]=stack[rear]; 41 l++; 42 rear--; 43 } 44 stack[++rear]=str[i]; 45 } 46 else 47 { 48 while(rear>=0 && stack[rear]!='(') 49 { 50 source[l]=stack[rear]; 51 l++; 52 rear--; 53 } 54 stack[++rear]=str[i]; 55 } 56 } 57 while(rear>=0) 58 { 59 source[l]=stack[rear]; 60 l++; 61 rear--; 62 } 63 for(i=0;i<l;i++) 64 printf("%c",source[i]); 65 printf("\n"); 66 } 67 return 0; 68 }