Cod sursa(job #3362890)

Utilizator horia.boeriuBoeriu Horia Andrei horia.boeriu Data 13 august 2026 01:57:37
Problema Sortare prin comparare Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.72 kb
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500000;
int v[MAXN];
int readInt(FILE *fin) {
    int x;
    char ch;
    ch = fgetc(fin);
    while (isspace(ch)) {
        ch = fgetc(fin);
    }
    x = 0;
    while (isdigit(ch)) {
        x = x * 10 + ch - '0';
        ch = fgetc(fin);
    }
    return x;
}
int main()
{
    FILE *fin, *fout;
    int n, i;
    fin = fopen("algsort.in", "r");
    n = readInt(fin);
    for (i = 0; i < n; i++) {
        v[i] = readInt(fin);
    }
    fclose(fin);
    sort(v, v + n);
    fout = fopen("algsort.out", "w");
    for (i = 0; i < n; i++) {
        fprintf(fout, "%d ", v[i]);
    }
    fprintf(fout, "\n");
    fclose(fout);
    return 0;
}