102. Pocket Calculator

Codeforces
IDCF10269102
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Pocket Calculator You have a pocket calculator. Unfortunately, it is broken, so you need to calculate large math operations yourself. For this problem, you need to write a computer program to calculate the answer to a long math operation, with multiplication (denoted by an asterisk *), division (denoted by a slash / ), addition, and subtraction. There will not be parentheses or exponents. Recall order of operations: multiplication and division (with equal weight) from left to right first, followed by addition and subtraction (with equal weight) from left to right. *Using eval() or similar commands for this problem is not allowed.* The only line of input contains a line of text representing a math operation to calculate. The math operation will consist of one-digit numbers and the four operations described above, with exactly one space between each one. The input line will start and end with a number, and there will *not* be an equals sign at the end of the operation. Output a single integer: the answer to the math operation. The answer is guaranteed to fit inside of a 32-bit signed integer type. The answer is also guaranteed to be an integer. In the third sample, $9. 0$ would also be judged as correct. ## Input The only line of input contains a line of text representing a math operation to calculate. The math operation will consist of one-digit numbers and the four operations described above, with exactly one space between each one. The input line will start and end with a number, and there will *not* be an equals sign at the end of the operation. ## Output Output a single integer: the answer to the math operation. The answer is guaranteed to fit inside of a 32-bit signed integer type. The answer is also guaranteed to be an integer. [samples] ## Note In the third sample, $9. 0$ would also be judged as correct.
**Definitions** Let $ E $ be a string representing a mathematical expression consisting of single-digit integers and operators $ \{+, -, *, /\} $, with exactly one space between each token. Let $ T = [t_0, t_1, \dots, t_{m-1}] $ be the list of tokens obtained by splitting $ E $ by spaces, where each $ t_i $ is either a digit (converted to integer) or an operator. **Constraints** 1. $ |T| \geq 1 $, and $ |T| $ is odd. 2. Tokens at even indices (0-indexed) are integers in $ \{0, 1, \dots, 9\} $. 3. Tokens at odd indices are operators in $ \{+, -, *, /\} $. 4. The expression contains no parentheses or exponents. 5. The result is guaranteed to be an integer within the range of a 32-bit signed integer. **Objective** Compute the value of $ E $ following standard order of operations: - First, evaluate all $ * $ and $ / $ operations **left to right**. - Then, evaluate all $ + $ and $ - $ operations **left to right**. Output the resulting integer.
API Response (JSON)
{
  "problem": {
    "name": "102. Pocket Calculator",
    "description": {
      "content": "Pocket Calculator You have a pocket calculator. Unfortunately, it is broken, so you need to calculate large math operations yourself. For this problem, you need to write a computer program to calcula",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10269102"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Pocket Calculator\n\nYou have a pocket calculator. Unfortunately, it is broken, so you need to calculate large math operations yourself. For this problem, you need to write a computer program to calcula...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ E $ be a string representing a mathematical expression consisting of single-digit integers and operators $ \\{+, -, *, /\\} $, with exactly one space between each token.  \n\nLet $...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments