Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Remove Duplicates

By shakilrana055 · Limits 1s, 512 MB

The problem is so simple. You are given a string and you have to remove all duplicate characters from the string and print the list of unique characters occurring in the input string, along with the number of occurrences each.

Input

The input starts with an integer T ( 1 <= T <= 5 ) denoting the number of testcases. Every testcases contain a non-empty string s ( 1 <= |s| <= 100000 )

Output

For each case print the case number in the format “Case #X:” where ‘X’ should be replaced with case number. then print a new line. Then sequence of ordered pairs, separated by new lines. The first element of the pair must be a character from the input string. The second element must be the number of occurrences that particular character appeared in that string. The elements in each pair are to be separated by space. The characters are to appear in the order in which they were contained in the input string. See the sample I/O for better explanation.

Sample

InputOutput
2
book
madam
Case #1:
b 1
o 2
k 1
Case #2:
m 2
a 2
d 1

Discussion

Statistics


86% Solution Ratio

MarzukEarliest, May '19

Alamin_justFastest, 0.0s

Alamin_justLightest, 131 kB

mdgaziur001Shortest, 113B

Submit

Login to submit