Data structure Experiment stack three: suffix-type evaluation (stack)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.