#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 1000
using namespace Std;
Char s[n];//Store string
Char str1[n];//store ' o '-characters to ' 9 '
Char str2[n];//storage operator
int top1,top2;//using an array simulation stack
int compare (char x)//Priority comparison
{
Switch (x)
{
Case ' + ':
Case '-': return 1;
Case ' * ':
Case '/': return 2;
Case ' (': return 0;
default:return-1;
}
}
void Zhuan ()//conversion
{
int k;
top1=-1,top2=-1;//Initialization Header
scanf ("%s", s);
K=strlen (s);
for (int i=0;i<k;i++)
{
if (s[i]>= ' 0 ' &&s[i]<= ' 9 ' | | s[i]== '. ')
{
top1++;
Str1[top1]=s[i];
}
else if (s[i]== ' (')
{
top2++;
Str2[top2]=s[i];
}
else if (s[i]== ') ')
{
while (str2[top2]!= ' (')
{
top1++;
Str1[top1]= ";
top1++;
STR1[TOP1]=STR2[TOP2];
top2--;
}
top2--;;
}
else if (s[i]== ' + ' | | s[i]== '-' | | s[i]== ' * ' | | s[i]== '/')
{
top1++;
Str1[top1]= ";
while (compare (S[i]) <=compare (STR2[TOP2]))
{
top1++;
STR1[TOP1]=STR2[TOP2];
top1++;
Str1[top1]= ";
top2--;
}
top2++;
Str2[top2]=s[i];
}
}
while (Top2!=-1)
{
top1++;
Str1[top1]= ";
top1++;
STR1[TOP1]=STR2[TOP2];
top2--;
}
top1++;
Str1[top1]= ";
top1++;
str1[top1]= ' = ';
top1++;
str1[top1]= ' + ';
for (int i=0;i<top1;i++)
printf ("%c", Str1[i]);
printf ("\ n");
}
Main ()
{
int n;
scanf ("%d", &n);
while (n--)
{
Zhuan ();
}
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Nanyang OJ infix variable suffix type title 467 data structure Nyoj