DCEPC207 - Finally a Treat

Anuja ma’am is getting more and more obsessed by her name (actually she loves it!!!). She has a strong belief that her name has something very special but she could not make it out what is it. As Vaibhav sir is very good in finding pattern he helped her with her problem, that she has a name in which only one character has maximum frequency i.e. ‘a’. She became very happy and decided to give a party to all of the members of DCE Coders who have special names. But wait, she finds out that the list is too big, so she decided to narrow it down. Here's how she narrows it: “Anuja ma’am will give a party to all those whose name is special and the character which makes their name special MUST be the character with maximum frequency in the entire list of names. There is only ONE special character in the string.”

As a student you are required to make a list of names ELLIGIBLE for party.

Remember, a name is special only if a SINGLE character has the maximum frequency in it. (See example #2 )

Input

1st line contains T(1<=T<=100), number of test cases. Next T lines contain a string(1<=Length of String<=10000) containing list of names separated by SPACES.

Output

Output k+1 lines for each test case, where k is the number of students ELLIGIBLE. First line contains “Case #x:” where x is the case number starting from 1. Then next k lines contain the names of ELLIGIBLE students.

Note: Each input string will have at least 1 word (of at least 1 character). i.e. there is no input string with only spaces

Example

Input:
2
abcdd abccd cccd
aabb aabcc aaa adaa Output: Case #1:
abccd
cccd
Case #2:
aaa
adaa

Added by:dce coders
Date:2012-02-26
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own Problem

hide comments
2012-03-28 15:03:35 neerajcrespo
can there be multiple spaces or tab between two words?
2012-03-17 02:41:13 well i am lagging
sorry mitch, I will take care of it next time, actually I posted my problem on forum but it didn't got entertained so was curious where I am wrong.
2012-03-16 22:29:17 Mitch Schwartz
@lagging: Mm, I think it is bad etiquette to post the same question twice in the same day, and to put my name there like it's urgent for me to answer you.

What is it about those particular cases that is causing you confusion? Maybe if you explain the confusion, it can be addressed directly. As it is, you are basically just asking for help debugging. You can try SPOJ forums for that. The comments section is not the right place for it.
2012-03-16 06:15:23 Mitch Schwartz
@lagging: The problem description clearly guarantees that "There is only ONE special character in the string". You have provided two invalid test cases. Not every name is guaranteed to be special. Read the problem description carefully.
2012-03-16 05:51:02 well i am lagging
what should the output of
a b c d
aac aca cbb bcb
2012-03-16 05:39:21 well i am lagging
@mitch each name has it's own special character and special character which is special character for max names, we o/p them, but in case of tie, you are saying, we need to consider entire string, I am not getting this part.
2012-03-16 00:13:54 Mitch Schwartz
I got AC under the assumption that we should preserve the order of the names as given in the input.

Regarding ties: You have misunderstood the problem. Considering the case

aab aab bba bbc

to find the special character of the entire string, do not consider "aabb", rather consider "aabaabbbabbc".

Last edit: 2012-03-16 01:03:40
2012-03-13 18:47:38 saket diwakar
there is something wrong with the description....when i took string length as 10010 it got AC...bt WA with 10000..
2012-03-11 19:05:35 Noszály Csaba
I assume that Anuja wants as
large party as possible, but what must we do in case of a tie i.e.:
aab aab bba bbc
And what is the expected order of outputting names (lexicographic or preserving the order of input)

OFF: If any hindi people here knows the (approximate) meaning of name KISHUN, please let me know.
2012-03-07 15:53:24 RAJDEEP GUPTA
What does it mean by "There is only ONE special character in the string"? I mean for "aa aa aa cccc" what is the ans? is it "cccc" or the 3 "aa"-s??

EDIT: it is the 3 "aa"-s. NOT "cccc".

Last edit: 2012-03-11 12:49:18
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.