DCP-160: Electricity Failure Back to All Problems

Medium Recursion > Parsing/Grammar

Yesterday, Jubaer was in IITLab-402 and writing a simple C code. Let’s have a look at his code- #include <stdio.h> int f(int a, int b) { return a + b; } int g(int a, int b) { return a * b; } int main(){ printf("%d\n”,f(g(2,3),5)); return 0; } When he wanted to run the code, electricity failure ruined it. He became very sad and I tried to make him understand that it’s not necessary to run a simple code while the result can be calculated by hand. He became angry and gave me hundreds of such codes. As I have a Laptop, can you please help me to calculate the outputs of such codes? You will be given only the function calling expression and you have to calculate the results. Input: ------ Input starts with an Integer **T**, denoting the number of test cases. Each of next **T** lines contains a function calling expression. It is guaranteed that numbers are in range **[0,9]**. It is also guaranteed that there is no extra characters except ‘**f**’, ‘**g**’, ‘**(**‘, ‘**)**’, '**,**' and **digits** and output will always feet into a 32 bit signed integer. Here, 1 <= **T** <= 20 and 1 <= **Length of expression** <= 500 Output: ------- For each case print **Case X: Y**, where **X** is the case number and **Y** is the expected result. For invalid expression print **-1**. Sample Input ------------ 3 f(g(2,3),5) f(4,f(g(2,3),f(5,3))) f(2,5,8) Sample Output ------------- Case 1: 11 Case 2: 18 Case 3: -1

Problem Setter:

Feroz Ahmmed

Please login to submit solution to this problem.

Problem Limits

Language Time Limit (seconds)
C 1.00
C++ 1.00
C++14 1.00
C# 3.00
Go 3.00
Java 3.00
JavaScript 3.00
Objective-C 3.00
Perl 3.00
PHP 3.00
Python 3.00
Python3 3.00
Ruby 3.00
VB.Net 3.00

Problem Stats




# User Language Timing
01 seyedssz Cpp14 0.00s
02 feodorv C 0.00s
03 Robbinb1993 Cpp14 0.00s
04 tariqiitju Cpp 0.00s
05 Tahmid Cpp14 0.00s
06 Morass Cpp14 0.01s
07 gbriyad Cpp14 0.22s
08 Unseen Cpp14 0.26s
09 template Cpp14 0.33s
10 Zeronfinity Cpp14 0.37s
11 holahmeds Cpp14 0.39s
12 smjlord068 Cpp14 0.48s
13 froghramar Cpp14 0.50s
14 ahqmrf Cpp14 0.50s
15 Masum_ice Cpp14 0.51s
16 habib_rahman Cpp14 0.53s
17 Jakir_Hossain_Sust Cpp14 0.54s
18 I_See_You Cpp14 0.57s
19 fsshakkhor Cpp14 0.57s
20 imAnik Cpp14 0.58s
21 anowar1112 Cpp14 0.58s
22 Apu_hasan Cpp14 0.64s
23 dragon Cpp14 0.65s
24 Knight_King Cpp14 0.65s
25 Double_O Cpp14 0.66s

Your feedback is our precious!

Or call +88 02 9853138 for support