Cod sursa(job #1315752)

Utilizator japjappedulapPotra Vlad japjappedulap Data 13 ianuarie 2015 01:34:51
Problema Nums Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <fstream>
#include <string>
#include <set>
using namespace std;

ifstream is ("nums.in");
ofstream os ("nums.out");

int N;
struct CMP
{
    bool operator ()(const string& a, const string& b)
    {
        if (a.length() < b.length())
            return 1;
        else
        {
            if (a.length() == b.length())
                return a < b;
            return 0;
        }
    }
};
set <string, CMP> S;

int main()
{
    is >> N;
    string x;
    for (int i = 1, OP, pos; i <= N; ++i)
    {
        is >> OP;
        if (OP == 1)
        {
            is >> x;
            S.insert(x);
        }
        else
        {
            is >> pos;
            auto it = S.begin();
            advance(it, pos-1);
            os << *it << '\n';
        }
    }
};