PROBLEM STATEMENT
Given a String, find all pairs of letters. A pair is considered to be two
letters that are equivalent, regardless of case (so "Aa" contains a pair of
'a's). Once a letter is used to make a pair, it can not be used in another
pair. "aaa" only has one pair of 'a's, and an extra 'a' which is left
unpaired. "aaaa" has two pairs of 'a's.
Create a class Pairs that contains the method countPairs, which takes as input
a String word, and returns the number of letter pairs found.
DEFINITION
Class: Pairs
Method: countPairs
Parameters: String
Returns: int
Method signature (be sure your method is public): int countPairs(String word);
TopCoder will ensure the validity of the inputs. Inputs are valid if all of
the following criteria are met:
- word is a String of length 0 to 49 inclusive
- word contains only digits '0'-'9', letters 'a'-'z', 'A'-'Z', and spaces ' '
NOTES:
- A pair is considered to be two letters that are equivalent, regardless of
case, so "Aa" has a pair of 'a's.
- Once a letter is used to make a pair, it can not be used in another pair.
"aaa" only has one pair of 'a's, and an extra 'a' which is left unpaired.
- Pairs of digits or spaces are not counted, and hence will not add to the
total number of pairs found.
EXAMPLES
1)
word = "Aa"
Method return 1
1 pair of 'a's is found.
2)
word = "Aa9a"
Method return 1
3 'a's are found, forming one pair and a leftover 'a'.
3)
word = "Aa9a cD 9A"
Method return 2
4 'a's are found, 2 '9's are found, 2 spaces are found, no other pairs are
found. The pair of '9's and spaces are ignored because they are not letters,
hence 4/2 = 2 pairs.