Home > Back-end >  The output noise problem
The output noise problem

Time:09-26

Error should be because of memory, but I don't know how to change, modify, thank you,
 # include 
#include
#include
# define size_new 100
# define size_malloc 500
Typedef struct node {
Char * head;
Char * lead;
Int size_head_lead;
Int size_head_lead_1;
} Sqstack;
Void init (Sqstack * S)
{
S - & gt; The head=(char *) malloc (sizeof (char) * size_malloc);
if(! S - & gt; The head)
exit(0);
S - & gt; Lead=S - & gt; The head;
S - & gt; Size_head_lead_1=size_malloc;
S - & gt; Size_head_lead=0;
}
Void push (Sqstack * S, char st_r)
{
S - & gt; Lead [S - & gt; size_head_lead]=st_r;
S - & gt; Size_head_lead + +;
}
Pop (Sqstack is void * S)
{
Printf (" % c ", S - & gt; Lead [S - & gt; size_head_lead - 1));
S - & gt; Size_head_lead -;
}
Int main (void)
{
Sqstack S;
Init (& amp; S);
Char zifu [200].
While (the scanf (" % s ", zifu)!=(EOF)
{
for(int i=0; i {
If (zifu [I] & gt;=65 & amp; & Zifu [I]
=90)Printf (" % c ", zifu [I]);
If (S.s ize_head_lead==0)
Push (& amp; S, zifu [I]);
If ((zifu [I]=='+' & amp; & S.l ead [S.s ize_head_lead - 1]=='*') | | (zifu [I]=='+' & amp; & S.l ead [S.s ize_head_lead - 1]=='/') | | (zifu [I]=='-' & amp; & S.l ead [S.s ize_head_lead - 1]=='*') | | (zifu [I]=='-' & amp; & S.l ead [S.s ize_head_lead - 1]=='/') | | (zifu [I]=='-' & amp; & S.l ead [S.s ize_head_lead - 1]=='-') | | (zifu [I]=='-' & amp; & S.l ead [S.s ize_head_lead - 1]=='+') | | (zifu [I]=='+' & amp; & S.l ead [S.s ize_head_lead - 1]=='-') | | (zifu [I]=='+' & amp; & S.l ead [S.s ize_head_lead - 1]=='+'))
{
While (S.l ead [S.s ize_head_lead - 1].='(')
{
Pop (& amp; S);
}
Push (& amp; S, zifu [I]);
}
If ((zifu [I]=='*') | | (zifu [I]=='/') | | (zifu [I]=='('))
{
Push (& amp; S, zifu [I]);
}
If (zifu [I]==') ')
{
While (S.l ead [S.s ize_head_lead - 1].='(')
{
Pop (& amp; S);
}
S.s ize_head_lead -;
}
}
}

return 0;
}

The Description


Expression to facilitate the processing, often converts regular expressions (called infix) suffix {operators, such as written, Y/X/Y expression, can need not parentheses in such said can determine the order of evaluation, such as: (P + Q) * (R, S) -> PQ + RS - *, postfix expression process is as follows: scan the postfix expression, every encounter operand will press it into the stack, in case the operator is from the stack pop-up two operands for the operation, the operation results pressure stack, and then continue to scan, until completion of the postfix expression was scanning, the bottom of stack elements is the value of the postfix expression,

Enter a infix expression, programming outputs the postfix expression, sequence of required output suffix expression in accordance with the input order of infix expression, for the sake of simplicity, assume that the input infix expression by the + (plus), - (minus), x (take),/(except) four operation as well as the left and right parentheses and English letters, symbols of arithmetic operators follow after the first, add and subtract operation rules, assume that the input infix expression does not exceed 200 characters in length, and are correct, namely no grammatical errors, and who must be expression in its internal bracket, namely inside at least one sign of operation,

Input

Number of rows, each row corresponds to a infix expression

The Output

Number of rows, each row corresponds to a convert infix expression of postfix expression

The Sample Input
X + A * (Y - B) - Z/F
A + B * C + + (D * M, N) (S) * Y
A - B * C + (D - E * F)/G

The Sample Output
ZF XAYB - * +/-
ABC * N - + + DM * ST - * Y +
* - ABC DEF * - G/+

CodePudding user response:

Thank you very much
  • Related