Cod sursa(job #2322475)

Utilizator Andrei_CotorAndrei Cotor Andrei_Cotor Data 17 ianuarie 2019 20:18:17
Problema Tije Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.83 kb
#include<fstream>
using namespace std;

class OutParser {
private:
    FILE *fout;
    char *buff;
    int sp;

    void write_ch(char ch) {
        if (sp == 50000) {
            fwrite(buff, 1, 50000, fout);
            sp = 0;
            buff[sp++] = ch;
        } else {
            buff[sp++] = ch;
        }
    }


public:
    OutParser(const char* name) {
        fout = fopen(name, "w");
        buff = new char[50000]();
        sp = 0;
    }
    ~OutParser() {
        fwrite(buff, 1, sp, fout);
        fclose(fout);
    }

    OutParser& operator << (int vu32) {
        if (vu32 <= 9) {
            write_ch(vu32 + '0');
        } else {
            (*this) << (vu32 / 10);
            write_ch(vu32 % 10 + '0');
        }
        return *this;
    }

    OutParser& operator << (long long vu64) {
        if (vu64 <= 9) {
            write_ch(vu64 + '0');
        } else {
            (*this) << (vu64 / 10);
            write_ch(vu64 % 10 + '0');
        }
        return *this;
    }

    OutParser& operator << (char ch) {
        write_ch(ch);
        return *this;
    }
    OutParser& operator << (const char *ch) {
        while (*ch) {
            write_ch(*ch);
            ++ch;
        }
        return *this;
    }
};

ifstream fi("tije.in");
OutParser fo("tije.out");
int n,i,j,k;
int main()
{
    fi>>n;
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=i; j++)
            fo<<i<<" "<<n+1<<"\n";
        for(j=i+1; j<=n; j++)
        {
            for(k=1; k<=j-2; k++)
                fo<<j<<" "<<i<<"\n";
            fo<<j<<" "<<n+1<<"\n";
            for(k=1; k<=j-2; k++)
                fo<<i<<" "<<j<<"\n";
            fo<<i<<" "<<j<<"\n";
        }
        for(j=1; j<=n; j++)
            fo<<n+1<<" "<<i<<"\n";
    }
    fi.close();
    return 0;
}