Cod sursa(job #1315754)

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

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

#define BF 1<<20
char Pars[BF], *p;
int GET();
int GETX();
void Check();
string X;

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()
{
    p = Pars;
    N = GET();
    for (int i = 1, OP, pos; i <= N; ++i)
    {
        OP = GET();
        if (OP == 1)
        {
            GETX();
            S.insert(X);
        }
        else
        {
            pos = GET();
            auto it = S.begin();
            advance(it, pos-1);
            os << *it << '\n';
        }
    }
};

int GETX()
{
    X = "";
    while (*p < '0' || *p > '9') ++p, Check();
    while (*p >= '0' && *p <= '9') X += *p, ++p, Check();
};

int GET()
{
    int X = 0;
    while (*p < '0' || *p > '9') ++p, Check();
    while (*p >= '0' && *p <= '9') X = X*10 + (*p - '0'), ++p, Check();
    return X;
};

void Check()
{
    if (*p == '\0') is.get(Pars, BF, '\0'), p = Pars;
};