Data structure Experiment stack three: suffix-type evaluation Time limit:1000ms Memory limit:65536k Title description for a suffix expression based on the two-tuple operator (the base operand is a positive integer), the value of the arithmetic expression to be represented. Enter a suffix string to enter an arithmetic expression with ' # ' as the end flag. The output evaluates the value of the arithmetic expression corresponding to the suffix and outputs it. Sample input
59*684/-3*+#
Sample output
57
1#include <stdio.h>2#include <string.h>3#include <iostream>4#include <algorithm>5#include <stack>6 using namespacestd;7 8 intMain ()9 {Tenstack<int>Q; One intI, t=0, f=0, Len; A Chars[10000]; -scanf"%s", s); -Len =strlen (s); the for(i=0; i<len; i++) - { - if(s[i]=='#') - { +printf"%d\n", Q.top ()); - Break; + } A if(s[i]>='0'&& s[i]<='9') at { -t = s[i]-'0'; - Q.push (t); - } - Else - { inf =q.top (); - Q.pop (); tot =q.top (); + Q.pop (); - if(s[i]=='+') thet = t+F; * if(s[i]=='-') $t = tF;Panax Notoginseng if(s[i]=='*') -t = t*F; the if(s[i]=='/') +t = t/F; A Q.push (t); the } + } - return 0; $}
Data structure Experiment stack three: suffix-type evaluation (stack)