algorithm training prefix expressionTime limit: 1.0s memory limit: 512.0MB The problem description writes a program, enters a prefix expression as a string, and then computes its value. The input format is: "Operator Object 1 Object 2", where the operator is "+" (addition), "-" (subtraction), "*" (multiplication), or "/" (division), and the operands are integers of not more than 10, separated by a space. Requirements: for addition, subtraction, multiplication, in addition to these four kinds of operations, respectively, design the corresponding function to achieve.
Input format: Enter only one row, which is a prefix expression string.
Output format: Outputs the corresponding calculation results (in the case of division, the C-language "/" operator is used directly, and the result is an integer).
Input and Output Sample sample input + 5 2 sample Output 7
#include <iostream>#include<cstdio>using namespacestd;intMain () {CharC; intn,m; scanf ("%c",&c); scanf ("%d%d",&n,&m); if(c=='+') printf ("%d\n", n+m); if(c=='-') printf ("%d\n", N-m); if(c=='*') printf ("%d\n"Nm); if(c=='/') printf ("%d\n", n/m); return 0;}
Blue Bridge Cup-algorithm training prefix expression