Problem Statement
The layout is given as a rectangular grid of 1 x 1 areas, each shown as a single character. Each uppercase letter represents the color of a 1 x 1 part of a tile. An area that is not occupied by a tile is indicated with the character '-'. No two tiles have a common border (but they may touch at a single point).
For example, if the layout is
B-A-A-
AB--BA
-A-A-B
A-AB--
--B---
then there are 5 tiles, but only 3 distinct tiles, since the two tiles consisting
of just 'A' are the same, and the two 4-square tiles in the upper left and
upper right are the same (but different from the bottommost tile).
Create a class Distinct that contains a method count that is given a String[] layout and that returns the number of distinct tiles in the layout.
Definition
- Class:
- Distinct
- Method:
- count
- Parameters:
- String[]
- Returns:
- int
- Method signature:
- int count(String[] layout)
- (be sure your method is public)
Constraints
- layout will contain between 1 and 50 elements, inclusive.
- Each element of layout will contain the same number of characters.
- Each element of layout will contain between 1 and 50 characters, inclusive.
- Each character in each element of layout will be '-' or an uppercase letter 'A'-'Z'.
Examples
{"B-A-A-","AB--BA","-A-A-B","A-AB--","--B---"}Returns: 3
This is the example shown above.{"A-B-C-D---"}Returns: 4
All 4 tiles are the same shape, a 1x1 square, but each has its own distinct color.{"AB-BA-AB-BA-ABBA"}Returns: 2
All the two-character tiles are the same, but of course are different from the 4-character tile.{"C---DC", "DCD-C-", "--C-DC", "------", "DCD---", "C-C--C", "---DCD", "--C--C", "DCD---", "C---CD", "-----C", "D---CD", "CDC---", "--D---" }Returns: 5