Account
Draft saved on this device
▤ DescriptionOriginal CppValley problem
Design PatternsEasy

Build A Strategy Based Arithmetic Calculator

Implement a command-driven calculator with interchangeable operations ADD, SUB, MIN, MAX.

Implement a command-driven calculator with interchangeable operations ADD, SUB, MIN, MAX. For every command, apply the requested arithmetic strategy to two signed integers and output the result.

Input format

First line Q; next Q lines OP a b, where OP is ADD, SUB, MIN or MAX.

Output format

Print one integer result for each operation.

Examples

Example 1
Input
4
ADD 2 9
SUB 2 9
MIN 2 9
MAX 2 9
Expected output
11
-7
2
9

Constraints

  • 0 ≤ Q ≤ 100000
  • -10^9 ≤ a,b ≤ 10^9
  • All results fit signed 64-bit.

Related concepts

Strategy Pattern

This early-access exercise uses standard input/output. More advanced concurrency challenges will use specialized class interfaces, instrumentation, and stress tests once the judging infrastructure is ready.

⌘ CodeC++17
GNU C++17 · main.cpp

Loading Monaco C++ editor…

Checking judge...

Checking whether the external C++ judge is available.

⌁ Test cases & resultsPublic samples: 1
Input
4
ADD 2 9
SUB 2 9
MIN 2 9
MAX 2 9
Expected output
11
-7
2
9
Execution requires a secure external judge.