Cod sursa(job #1982297)

Utilizator AlexAndrei11Mintas Alex Andrei AlexAndrei11 Data 18 mai 2017 09:49:19
Problema A+B Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    int n,aux,baza,a[1000],i,j;
    bool ok=false;

    ifstream fin("pietre.in");
    ofstream fout("pietre.out");

    cin>>baza;
    n=0;
    aux=baza;
    while (aux>=1)
    {
        n=n+aux;
        aux--;
    }
    for (i=1;i<=n;i++)
        fin>>a[i];
    while (ok==false)
    {
        ok=true;
        for (i=2;i<=n;i++)
            if (a[i-1]>a[i])
        {
            aux=a[i];
            a[i]=a[i-1];
            a[i-1]=aux;
            ok=false;
        }
    }
    fout<<a[1];
    fout<<endl;
    i=2;
    for (aux=2;aux<=baza;aux++)
        {
            for (j=1;j<=aux;j++)
            {
                fout<<a[i]<<" ";
                i++;
            }
            fout<<endl;
        }

    fin.close();
    fout.close();
    return 0;
}