12536 - People nowadays
raw download clone
CPP
views 6
,
size 1533 b
#include <iostream>
#include <utility>
#include <string>
#include <map>
#include <set>

using namespace std;

struct person{
    int age;
    string name;
    person(int _age, string _name): age{_age}, name{_name} {}

    bool operator < (const person &rhs)const{
        if(age == rhs.age){
            return (name < rhs.name);
        }
        else{
            return (age < rhs.age);
        }
        return false;
    }
};

int main()
{

    set<person> Set;
    int n;
    cin>>n;
    while(n--){
        string temp;
        cin>>temp;
        if(temp == "born"){
            string name;
            int age;
            cin>>name>>age;
            person newPerson{age, name};
            Set.insert(newPerson);
        }
        else if(temp == "find"){
            string name;
            int age;
            cin>>name>>age;
            person findPerson{age, name};
            if(Set.find(findPerson) == Set.end()){
                cout<<"NO\n";
            }
            else{
                cout<<"YES\n";
            }
        }
        else if(temp == "kill"){
            string name;
            int age;
            cin>>name>>age;
            person beKilledPerson{age, name};
            if(Set.find(beKilledPerson) != Set.end()){
                Set.erase(Set.find(beKilledPerson));
            }
        }
        else if(temp == "young"){
            cout<<Set.begin()->name<<" "<<Set.begin()->age<<"\n";
        }
    }
    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.