Cod sursa(job #2262499)

Utilizator stefanut999Paul Colta stefanut999 Data 17 octombrie 2018 15:11:58
Problema Sortare prin comparare Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.63 kb
#include <fstream>
#include <climits>
using namespace std;
ifstream fin("algsort.in");
ofstream fout("algsort.out");
#define NMAX 500001
int n,v[NMAX];

void citire()
{ fin>>n;
 int i;
 for(i = 1; i <= n; i++)
    fin>>v[i];

}

void rezolvare()
{citire();
 int i,j,maximao,p,aux,t = n;
 while(n)
 {maximao = INT_MIN;
  for(i = 1; i <= n ; i++)
    if(maximao < v[i])
    {maximao = v[i];
     p = i;
    }
  aux = v[n];
  v[n] = v[p];
  v[p] = aux;
  n--;
    }
 for(i = 1; i <= t; i++)
    fout<<v[i]<<' ';
}


int main()
{
    rezolvare();
    fin.close();
    fout.close();

    return 0;
}