#C10553. Valid Arithmetic Expression Checker
Valid Arithmetic Expression Checker
Valid Arithmetic Expression Checker
Given an arithmetic expression as a string, determine whether it is valid under the following rules:
- The expression consists only of non-negative integers and the operators
+
,-
,*
, and/
. - The expression must start and end with a digit.
- There cannot be consecutive operators.
- Operands must not have leading zeros unless the operand is exactly
0
. - Division by zero is not allowed.
Your task is to read the expression from standard input and print True
if the expression is valid and False
otherwise.
Note: If the expression is empty, it is considered invalid.
inputFormat
Input is read from standard input (stdin) and consists of a single line containing the arithmetic expression string.
outputFormat
Output to standard output (stdout) a single line: either True
if the expression is valid or False
otherwise.## sample
12+34*5-6/2
True