Name, age, and id. That is the information that we are supposed to have for
all our workers, but what we have is a mess. Our data is a collection of records,
but some workers have multiple records, and some of the records are missing
some of the information. We would like to untangle the mess. At least, we
would like to figure out how many different workers we have!
Each worker has his own unique id that is a string of digits, the first of
which is always zero ('0'). Each worker has a name consisting of uppercase
letters 'A'-'Z', and has an age that is an integer with no leading zeros. Neither
name nor age can be relied upon to be unique. Each data
record contains information for a single worker, and is formatted to contain
no leading or trailing spaces. It may contain 1, 2, or all 3 of the
fields (name, age, id) in any order. The fields within a record will be
separated by one or more spaces.
Create a class DataFilter that contains a method untangle that is
given a String[] data that contains the
records and returns the number of different workers we have.
Each element of
data consists of one or more records, separated from each other by a single semicolon (';'). If there is more
than one way to untangle the data, return the smallest possible
number of workers. If there is no consistent interpretation of the data,
return -1.
|