Java Code for No More Symbols (TCS Codevita) | PrepInsta

No More Symbols

TCS CodeVita is a coding competition organized by TCS every year, in search of world’s best coder. This is a global level coding competition in which coders from all around the world compete for the title of World’s Best Coder. No More Symbols is one of the sample problem of this year TCS CodeVita season 11 competition. 


Question -: Prabhu excels at typing letters but struggles with symbols and numbers. To simplify, he decided to represent mathematical expressions using words. For numbers, he mentions each digit individually with the character ‘c’ to signify the entire word representing the number. Prabhu exclusively uses lowercase letters as he’s not proficient with shift keys or caps lock.
For instance
111 is written as oneconecone
120 is written as onectwoczero
For a single operation: Operation Operand1 Operand2
Example: “add one two” represents 1+2.
For two functions: Operation1 Operation2 Operand1 Operand2 Operand3
Example: “add mul twoctwo threecone two” equals (22*31)+2.
For another variation: Operation1 Operand1 Operation2 Operand2 Operand3
Example: “add oneconecone div onectwoczeroczero twoctwo” equals 111+(1200/22).
Prabhu uses the following operations:

  • add for addition (e.g., 2+2=4).
  • sub for subtraction (e.g., 2-2=0).
  • mul for multiplication (e.g., 2*2=4).
  • rem for remainder (e.g., 2%2=0).
  • pow for power (e.g., 2^2=4).
To convert and evaluate Prabhu’s mathematical expression, output the result in numbers. If any word cannot be resolved as an operation or operand during evaluation, print “expression evaluation stopped invalid words present” If all words are recognized but the expression cannot be solved, print “expression is not complete or invalid”.

  • The input does not contain float or negative numbers.
  • Verify the correctness of words first, followed by correctness of expression.
0 < Characters in the first line including space < 100
0 < Operands in the expression < 20
Single line denoting the expression.
Single integer repersenting the result of the expression evalutated in numbers not in words.
Time Limit (secs)
Example 1
add one sub twochundered one
expression evaluation stopped invalid words present
In word twochundred, hundred is not a valid word only zero to nine can be used.

Example 2
five mul six six fourcninecnine zero
expression is not complete or invalid
Everywords in the expression is valid but the expression cannot be evaluated only mul operation is found there. After executing, there are still other words are left so the expression is not complete or invalid.

Example 3
mul add sub six five oneczero two
The above prabhu expression represents ((6-5)+10)*2.