Sphere Online Judge

SPOJ Problem Set (classical)

4897. Meowist Networking

Problem code: MEOWIST

Kat Mandu has been living in seclusion for several years, practicing martial arts and meditating. As a consequence, he missed the take-off of social networking. He was therefore surprised upon his return to society that countless many are standing with signs at every street corner, eager to be followed on Twitter; his grandmother runs one of the world's top blogs; and chances are, even your mom has Facebook.

Reluctantly, he joined the craze, but he quickly discovered that many of these services are lacking in their friend sorting facilities: they will usually only allow listing friends in alphabetical order by name. Kat Mandu would prefer sorting his friends by age, with the oldest at the top of the list. If two friends have the same age, only then sort alphabetically. Help Kat Mandu by writing a program which implements this functionality.

Input

Each line of input will contain a name and an age, separated by a space. Names will be unique and consist of at most 10 uppercase letters. Ages will be between 1 and 100 inclusive.

Output

Print out the same names that were given in the input, but sorted according to Kat Mandu's requirements.

Example

Input:
DUCHESS 26
MARIE 8
BERLIOZ 8
TOULOUSE 7
THOMAS 28

Output:
THOMAS
DUCHESS
BERLIOZ
MARIE
TOULOUSE

Added by:Miorel Palii
Date:2009-10-02
Time limit:2s
Source limit:4096B
Languages:All except: ERL TECS
Resource:University of Florida Local Contest - September 27, 2009

hide comments
2009-11-26 08:22:56 Miorel Palii
Length of code is not proportional to ingenuity required to solve the problem :)

That said, I agree that this is a very straightforward problem, but I also think there should be problems like these that newbie programmers can solve and have the satisfaction of more than 0.0 points.
2009-11-09 19:38:23 hu la la
2 lines in C++, excluding IO commands.
Should go to tutorial...
2009-10-25 11:50:50 Seshadri R
If no terminating input is given in the problem, then assume EOF (CTRL-D in Linux and CTRL-Z in Windows, if you test your program through keyboard input)
2009-10-19 05:41:22 Anirudh
How does the input terminate ?
2009-10-09 16:34:01 Miorel Palii
Yes, that is correct.
2009-10-09 01:48:56 Yonny Mondelo Hernandez (UCI-CU)
Case:
Name1: "DUCH" and Name2: "DUCHESS" example...
Name2 > Name1 ??? (Name1 show first)
SPOJ System © 2008-2010 Sphere Research Labs. All Rights Reserved.