TopCoder problem "SearchDisks" used in TCHS07 Alpha Round 1 (Division I Level One)



Problem Statement

    You have a lot of CDs that you have placed into one big box. You are given a String diskNames containing a single-space separated list of the disk names (the names will not contain spaces). The first disk is at the bottom of the box, the second lies directly on top of the first disk, and so on. Return the number of disks you'll need to take out of the box to find the disk named searchingDisk. You only need to take out the disks that are on top of searchingDisk. You do not need to take out the disk you're looking for.
 

Definition

    
Class:SearchDisks
Method:numberToTakeOut
Parameters:String, String
Returns:int
Method signature:int numberToTakeOut(String diskNames, String searchingDisk)
(be sure your method is public)
    
 

Constraints

-diskNames will contain between 1 and 50 characters, inclusive.
-searchingDisk will contain between 1 and 10 characters, inclusive.
-diskNames will contain only lowercase letters ('a'-'z') and spaces (' ').
-searchingDisk will contain only lowercase letters ('a'-'z').
-Disk names will be separated by exactly one space in diskNames.
-searchingDisk will be one of the disk names in diskNames.
-diskNames will not contain duplicate disk names.
-diskNames will not contain leading or trailing spaces
 

Examples

0)
    
"beatles queen abba"
"abba"
Returns: 0
It is not necessary to take out any disks. "abba" is already on top.
1)
    
"beatles queen abba"
"beatles"
Returns: 2
It is necessary to take out "abba" and then "queen" to get to "beatles".
2)
    
"a b c"
"b"
Returns: 1
3)
    
"t k o h z s v r i c e d n f a m u w p g j q x y l"
"f"
Returns: 11

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7525

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10702&pm=7525

Writer:

VitalyGoldstein

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Simple Search, Iteration, String Parsing