TopCoder problem "ToolsBox" used in SRM 453.5 (Division II Level One)



Problem Statement

    You are a carpenter and you want to build several pieces of furniture. Unfortunately, you've lost all your tools. You are given a String[] need, the i-th element of which is a space separated list of the tools required to construct the i-th piece of furniture. Return the number of different tools you must buy to construct all the furniture.
 

Definition

    
Class:ToolsBox
Method:countTools
Parameters:String[]
Returns:int
Method signature:int countTools(String[] need)
(be sure your method is public)
    
 

Constraints

-need will contain between 1 and 50 elements, inclusive.
-Each element of need will contain between 1 and 50 characters, inclusive.
-Each element of need will contain only uppercase letters ('A'-'Z') and spaces (' ').
-Each element of need will contain no leading, trailing, or consecutive spaces.
-For each element of need, all tool names in it will be distinct.
 

Examples

0)
    
{"SAW HAMMER SCREWDRIVER","SCREWDRIVER HAMMER KNIFE"}
Returns: 4
You need four tools: "SAW", "HAMMER", "SCREWDRIVER" and "KNIFE".
1)
    
{"SAW"}
Returns: 1
You need only "SAW".
2)
    
{"SAW","SAW"}
Returns: 1
Now you want to build two furniture items, but you need only "SAW" for both of them.

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=14174&pm=10461

Writer:

andrewzta

Testers:

PabloGilberto , ivan_metelsky , Vasyl[alphacom]

Problem categories:

Search