MEOWIST - Meowist Networking

no tags 

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

hide comments
Nallagatla Manikanta: 2015-10-28 09:19:22

learnt a new thing :)

karthik1997: 2015-07-15 19:32:54

ac 0.0s :p
use EOF to end the file and
simple use of linked lists :D and malloc :p
This shouldn't be int tutorials change it to classic:p

Last edit: 2015-07-15 19:34:21
Evan: 2014-12-10 05:39:38

why do i get compilation error ? i already use the right compiler.

karen: 2013-11-21 04:59:58

when the program ends?

npsabari: 2012-06-14 11:49:27

@Varun sharma : Thanks man!! Mine got accepted after ignoring empty strings

Varun Sharma: 2010-12-13 22:21:01

I am actually making an object and storing the names and age in it. When you are reading the input only create an object for age and name if the length of the name is greater than 0. Because you can have blank lines after the last name / age pair. Because of that you might read a empty string.

Seshadri R: 2010-03-04 03:06:30

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)

Anirudh: 2010-03-04 03:06:30

How does the input terminate ?


Added by:Miorel Palii
Date:2009-10-02
Time limit:1s
Source limit:4096B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL NODEJS OBJC PERL6 SQLITE VB.NET
Resource:University of Florida Local Contest - September 27, 2009