Expressions aritmètiques


Submit solution

Points: 10
Time limit: 5.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
C#, Go, Java

Implementa un intèrpret d'expressions aritmètiques.

Els operadors que ha d'implementar són:

+    Addició
-    Subtracció
*    Multiplicació
/    Divisió
%    Residu

Input Format

La entrada consisteix en el primer operand \(A\), l'operador \(Op\), i el segon operand \(B\), separats per espais en blanc.

Constraints

  • \(-100 <= A <= 100\)
  • \(-100 <= B <= 100\)
  • \(A\) i \(B\) són nombres decimals.

Output Format

El resultat de la operació (amb decimals), o els missatges Error: division by zero i Error: operation not permitted segons el cas.

Test Case 1

Input
1 + 1
Output
2.0

Test Case 2

Input
1 - 1
Output
0.0

Test Case 3

Input
100 * 100
Output
10000.0

Test Case 4

Input
5 / 10
Output
0.5

Test Case 5

Input
10 % 0.5
Output
0.0

Test Case 6

Input
10 / 0
Output
Error: division by zero

Test Case 7

Input
7 & 3
Output
Error: operation not permitted

Test Case 8

Input
27 % 0
Output
Error: division by zero

Authorship: Gerard Falcó

CC BY-NC-SA 4.0