Csu-1537:miscalculation (Simulated problem)

Source: Internet
Author: User

http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1537

Because the given formula is necessarily legal, just use two stacks to save the symbols and numbers. Compare the answers to the left-to-right answers.

1#include <iostream>2#include <cstdio>3#include <cmath>4#include <vector>5#include <cstring>6#include <algorithm>7#include <string>8#include <Set>9#include <functional>Ten#include <numeric> One#include <sstream> A#include <stack> -#include <map> -#include <queue> the  - #defineCL (arr, Val) memset (arr, Val, sizeof (arr)) -  - #definell Long Long + #defineINF 0x7f7f7f7f - #defineLC L,m,rt<<1 + #defineRC M + 1,r,rt<<1|1 A #definePi ACOs (-1.0) at  - #defineL (x) (x) << 1 - #defineR (x) (x) << 1 | 1 - #defineMID (L, R) (L + R) >> 1 - #defineMin (x, y) (x) < (y)? (x): (y) - #defineMax (x, y) (x) < (y)? (y): (x) in #defineE (x) (1 << (x)) - #defineIabs (x) (x) < 0? -(x): (x) to #defineOut (x) printf ("%i64d\n", X) + #defineLowbit (x) (x) & (-X) - #defineRead () freopen ("Din.txt", "R", stdin) the #defineWrite () freopen ("Dout.txt", "w", stdout); *  $ Panax Notoginseng using namespacestd; -  the intMain () + { A     //freopen ("A.txt", "R", stdin); the     Chars[ -]; +     intnum; -scanf"%s", s); $scanf"%d",&num); $stack<int>S1; -stack<Char>S2; -     intL=strlen (s); the      for(intI=0; i<l;i++) -     {Wuyi         if(s[i]>='0'&&s[i]<='9') S1.push (s[i]-'0'); the         Else if(s[i]=='*') -         { Wu             intx=s1.top (); S1.pop (); -             inty=s[i+1]-'0'; AboutS1.push (x*y); $i++; -         } -         ElseS2.push ('+'); -     } A      while(!s2.empty ()) +     { the         intx=s1.top (); S1.pop (); -         inty=s1.top (); S1.pop (); $S1.push (x+y); the S2.pop (); the     } the     intsum=s[0]-'0'; the      for(intI=1; i<l;i++) -     { in         if(s[i]=='+') sum=sum+ (s[i+1]-'0'); the         Else if(s[i]=='*') sum=sum* (s[i+1]-'0'); the     } About     //printf ("%d%d\n", s1.top (), sum); the     if(S1.top () ==sum&&sum==num) printf ("u\n"); the     Else if(S1.top ()!=num&&sum!=num) printf ("i\n"); the     Else if(S1.top () ==num&&sum!=num) printf ("m\n"); +     Else if(S1.top ()!=num&&sum==num) printf ("l\n"); -     return 0; the}

Csu-1537:miscalculation (Simulated problem)

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.