TopcoderArchiveVisit Topcoder
SRM20 Nov 2009
SRM 453.5

ToolsBox

Problem statement, definition, constraints, and public examples.

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

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