Rokua P1449 suffix expression Label: Expression Calculation series

Source: Internet
Author: User

Title Description

The so-called suffix expression refers to an expression in which the parentheses are no longer referenced, the operation symbol is placed after two operands, and all calculations are performed in the order in which they appear, strictly from left to right (regardless of operator precedence).

For example: The suffix expression of 5–2 +7 corresponds to: 3. 5. 2. -*7. [Email protected]. ' @ ' is the end symbol for the expression. ‘.’ Is the end symbol for the operand.

Input/output format

Input format:

Input: suffix expression

Output format:

Output: The value of an expression

Input and Output Sample input example # #:
3.5.2.-*[email protected]
Sample # # of output:
16
Description

String length, within 1000.

Code

1#include <iostream>2#include <cstring>3#include <cstdio>4#include <algorithm>5 #definell Long Long6 using namespacestd;7ll num[1005];8 stringstr;9 Ten voidCul (ll p,ll op) { One     if(op==0) num[p-1]=num[p-1]+Num[p]; A     if(op==1) num[p-1]=num[p-1]-Num[p]; -     if(op==2) num[p-1]=num[p-1]*Num[p]; -     if(op==3) num[p-1]=num[p-1]/Num[p]; the } -  - ll result () { - ll Op_nxt; +ll Len=str.length (), p=-1; -ll num_nxt=0; +      for(intI=0; i<len;i++){ A         if(str[i]>='0'&&str[i]<='9') num_nxt=num_nxt*Ten+ (str[i]-'0'); at         Else if(str[i]=='.'){ -num[++p]=num_nxt; -num_nxt=0; -         } -         Else{ -              in             if(str[i]=='+') op_nxt=0; -             if(str[i]=='-') op_nxt=1; to             if(str[i]=='*') op_nxt=2; +             if(str[i]=='/') op_nxt=3; -              theCul (p--, OP_NXT); *         } $     }Panax Notoginseng     returnnum[0]; - } the intMain () { + //freopen ("01.in", "R", stdin); ACin>>str; theprintf"%lld\n", result ()); +     return 0; -}
View Code

See here

Http://www.cnblogs.com/radiumlrb/p/5759319.html

Rokua P1449 suffix expression Label: Expression Calculation series

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.