Cod sursa(job #1816750)

Utilizator TincaMateiTinca Matei TincaMatei Data 26 noiembrie 2016 20:51:08
Problema Interclasari Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.8 kb
#include <cstdio>
#include <algorithm>

//mi se pare cinstit
const int MAX_VECT = 20000000;
int v[MAX_VECT];

#include <stdio.h>
#include <ctype.h>

class InParser {
private:
    FILE *fin;
    char *buff;
    int sp;

    char read_ch() {
        ++sp;
        if (sp == 4096) {
            sp = 0;
            fread(buff, 1, 4096, fin);
        }
        return buff[sp];
    }

public:
    InParser(const char* nume) {
        fin = fopen(nume, "r");
        buff = new char[4096]();
        sp = 4095;
    }

    InParser& operator >> (int &n) {
        char c;
        while (!isdigit(c = read_ch()) && c != '-');
        int sgn = 1;
        if (c == '-') {
            n = 0;
            sgn = -1;
        } else {
            n = c - '0';
        }
        while (isdigit(c = read_ch())) {
            n = 10 * n + c - '0';
        }
        n *= sgn;
        return *this;
    }

    InParser& operator >> (long long &n) {
        char c;
        n = 0;
        while (!isdigit(c = read_ch()) && c != '-');
        long long sgn = 1;
        if (c == '-') {
            n = 0;
            sgn = -1;
        } else {
            n = c - '0';
        }
        while (isdigit(c = read_ch())) {
            n = 10 * n + c - '0';
        }
        n *= sgn;
        return *this;
    }
} fin("interclasari.in");

int main() {
  int n, k, top;
  fin >> n;
  top = 0;
  for(int i = 0; i < n; ++i) {
    fin >> k;
    for(int j = 0; j < k; ++j) {
      fin >> v[top];
      ++top;
    }
  }

  std::sort(v, v + top); //daca mere heapuri de doua milioane, tre sa meara si cu sort
  FILE *fout = fopen("interclasari.out", "w");
  fprintf(fout, "%d\n", top);
  for(int i = 0; i < top; ++i)
    fprintf(fout, "%d ", v[i]);
  fclose(fout);
  return 0;
}