Dhapu and the Call Stack
All submissions for this problem are available.
Dhapu is greatly interested in programming. She likes to break her programs into functions or subroutines. But sometimes, she loses track of which function her program is executing and from which function was it called. So, she read about the Call Stack which is a hidden stack used in High-Level Programming Languages to store information about the active subroutines of a computer program. Can you help her keep track by becoming the Call Stack?
Program execution starts from the already running main() function (Function ID = 0). It ends execution when the closing return command is encountered.
The input consists of commands/queries. You need to process all commands in order and print output wherever necessary.
Queries can be of 3 types.
Jump - Call the function whose ID is passed. Here 'x' is the Function ID. Syntax: j x
Return - Return from current active function. Syntax: r
Print - Print the ID of the current active function. Syntax: p.
Print only output of Print Command on separate lines.
- 1 <= Number of Commands <= 1000
- 1 <= Function ID <= 10^8
Input: pj 153prpr . Output: 01530
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP 4.3.2, CPP 6.3, CPP14, JAVA, PYTH|
Fetching successful submissions
If you are still having problems, see a sample solution here.