Data Structure :Array Sorting Assessment
- Country :
Australia
PROBLEM: Consider a sorted array containing the letters COMPUTER
C/E/M/O/P/R/T/…
When a letter is added, you insert the letter in the correct place in the array, moving the other letters. If the letter is already in the array, insert it BEFORE the existing occurrence.
Continuing with the example above, let's add the letters BAT. The shaded cell is where the new letter is positioned:
Add B: B/C/E/M/O/P/R/T…
Add A: A/B/C/E/M/O/P/R/T…
Add T:A/B/C/E/M/O/P/R/T/T..
INPUT:
You'll process 5 lines of data. Each line will start with a positive number, N, followed by a space, and then a string, xxx. Into an empty array, insert each letter in the string, one at a time. Ignore non- letters and also, convert all lowercase letters into uppercase.
OUTPUT:
For each input line, print how many different letters occupied the Nth element of the array while the string was processed. For example, "2 Computer" has answer of 3: The different letters in position 2 of the array were O. M. and finally E. The input line "2 COMPUTER Bar" has an answer of 5: the different letters at position 5 were O, M. E. C, and B.
SAMPLE INPUT | SAMPLE OUTPUT |
---|---|
2 Computer | 1.3 |
COMPUTER bat | 2.5 |
3COMPUTER | 3.2 |
4ACSL is fun | 4.3 |
9 the xylophone | 5.4 |