Cod sursa(job #3357373)

Utilizator VladPislaruPislaru Vlad Rares VladPislaru Data 9 iunie 2026 09:38:21
Problema Sortare prin comparare Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

int main() {
    std::ifstream input("algsort.in");
    std::ofstream output("algsort.out");

    int n;
    try {
        input >> n;
    } catch (const std::exception& e) {
        std::cerr << "Error: unable to read input file" << std::endl;
        return 1;
    }

    std::vector<int> v;
    for (int i = 0; i < n; ++i) {
        int x;
        try {
            input >> x;
        } catch (const std::exception& e) {
            std::cerr << "Error: unable to read input file" << std::endl;
            return 1;
        }
        v.push_back(x);
    }

    std::sort(v.begin(), v.end());
    for (auto x: v) output << x << " ";

    return 0;
}