SPOJ MEOWIST

The Problem
This problem should be a practise problem

It took me 20mins to solve it =) , I am too rusted lately but hopefully I will post a new problem everyday from now on


#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>

using namespace std;

class person{
        public:
        int age;
        string name;
        person(int a,string b){age=a; name=b;}
};

bool operator< (person a,person b)
{
        if(a.age>b.age) return true;
        else if(a.age==b.age && a.name<b.name) return true;
       return false;
}

int main()
{

        string a;
        int b;
        multiset< person > people;
        while(cin>>a>>b)
        {
                person n(b,a);
                people.insert(n);
        }
        while(people.size())
        {
                cout<<people.begin()->name<<endl;
                people.erase(people.begin());
        }
        return 0;
}

1 comment to SPOJ MEOWIST

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>