BdOI 2013 National Problem 3

Discuss everything related to IOI here. For more general or advanced topics use CS forum.

Moderators:Labib, bristy1588

User avatar
bristy1588
Posts:92
Joined:Sun Jun 19, 2011 10:31 am
BdOI 2013 National Problem 3

Unread post by bristy1588 » Tue Jan 14, 2014 11:43 pm

Far over the misty mountains cold there was the great land of Shell. There lived many
wizards, elves, hobbits, dwarves, men and programmers. The programmers were a brave
bunch of people. Even though they didn't know much of magic like the wizards or crafts like
elves they were never afraid of computers, dragons (one of them even called himself
SnapDragon) or filthy orcs.
You have knocked on the great iron door of Shell with a gleaming hope to become a
programmer. Behold! The great programmers have asked you to complete a task to see how
courageous you are and what amazing power you are hiding beneath your fingers!
In Shell to ride and run the computers, programmers used an operating system called
Erlang. Erlang was a beautiful system and poets of Shell have written thousands of lines of
poetry about its beauty. But alas! It didn't have any graphical interface. For example, when
asked what files are there in the system, Erlang replies with something like this
computer $( A ( B C ( D ) ) )$
This means, inside the computer there is a folder named A, which contains two things - a file
B and a folder C. Inside folder C there is a file D.
But it's hard to navigate. For example, to access D one has to write the following commands:

cd A
cd C
touch D

Every time you want to go inside a folder you have to write cd X, where X is the name of the
folder. And give the file a touch to access it. Now your task is - given the reply from Erlang
and told which file you have to access, find how many lines of commands you have to write.

INPUT
The input file will contain only two lines. The first line of the input contains a single
character - the name of the file to access. After that a single line follows containing the reply
from Erlang. All file names and folder names are capital letter from A-Z. No two folders or
files will have the same name. The file you'll have to access will be always in the system.
Each folder name will always accompany with a left bracket $ '(' $and content of that folder will
end with a $ ')' $. Of course a folder can have many files and folders within it. They will be all
separated by a single white space. There will be a space between every $ " ( " $ and file name too.

OUTPUT
Print a single integer - how many lines of command you have to write to access it.


Sample Input

Code: Select all

I
computer ( A ( B C ( D ) E F G ( I ) ) )
Sample Output

Code: Select all

3
Bristy Sikder

Post Reply