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