Cod sursa(job #1892300)
| Utilizator | Data | 24 februarie 2017 21:10:29 | |
|---|---|---|---|
| Problema | Sortare prin comparare | Scor | 40 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.62 kb |
#include <fstream>
using namespace std;
int a[500005];
int main() {
ifstream fin("algsort.in");
ofstream fout("algsort.out");
int n, i, j, ok, x;
fin >> n;
for(i = 0; i < n; i++)
fin >> a[i];
ok = 0;
while(ok == 0) {
ok = 1;
for(i = 0; i < n - 1; i++) {
if(a[i] > a[i+1]){
ok = 0;
x = a[i];
a[i] = a[i+1];
a[i+1] = x;
}
}
}
for(i = 0; i < n; i++)
fout << a[i] << " ";
return 0;
}
