#include <stdio.h>
#include <stdlib.h>
struct shu{
int front;
int rear;
}OPND;
struct others{
char *base;
char *top;
int size;
}OPTR;
char bijiao(char x, char y) {
if (x == '+') {
if (y == '+' || y == '-' || y == ')' || y == '#')
return('>');
else
return('<');
}
if (x == '-') {
if (y == '+' || y == '-' || y == ')' || y == '#')
return('>');
else
return('<');
}
if (x == '*') {
if (y == '(')
return('<');
else
return('>');
}
if (x == '/') {
if (y == '(')
return('<');
else
return('>');
}
if (x == '(') {
if (y == ')')
return('=');
if (y == '+' || y == '-' || y == '*' || y == '/' || y == '%' || y == '(')
return('<');
}
if (x == ')') {
if (y == '+' || y == '-' || y == '*' || y == '/' || y == '%' || y == ')' || y == '#')
return('>');
}
if (x == '#') {
if (y == '+' || y == '-' || y == '*' || y == '/' || y == '%' || y == '(')
return('<');
if (y == '#')
return('=');
}
}
void main() {
int n, i, j, k, s[50], flag;
char sopnd[50][50], str[50],t;
scanf("%d", &n);
getchar();
for (i = 0;i < n;i++) {
flag = 0;
OPND.front = 0;
OPND.rear = 0;
OPTR.size = 50;
OPTR.base = (char *)malloc(OPTR.size * sizeof(char));
OPTR.top = OPTR.base;
*OPTR.top++ = '#';
for (j = 0;j < 50;j++)
s[j] = 0;
gets(str);
for (j = 0;str[j] != '#' || *(OPTR.top - 1) != '#';j++) {
if (str[j] >= '0' && str[j] <= '9') {
for (k = 0;(str[j] <= '9' && str[j] >= '0') || str[j] == '.';) {
sopnd[OPND.rear][k] = str[j];
j++;
k++;
}
sopnd[OPND.rear][k] = '\0';
OPND.rear++;
j--;
}
else {
t= bijiao(*(OPTR.top - 1), str[j]); {
if(t=='<') {
*OPTR.top++ = str[j];
}
if(t=='='){
OPTR.top--;
}
if(t=='>') {
for (;OPND.front < OPND.rear;OPND.front++) {
if (flag == 1)
printf(" %s", sopnd[OPND.front]);
else
printf("%s", sopnd[OPND.front]);
flag = 1;
}
printf(" %c", *--OPTR.top);
j--;
}
}
}
}
printf("\n");
}
}
03-16
2991
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-09
1812
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-09
5004
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-30
782
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)