include stdafx include math include iostream using namespace std int i

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "stdafx.h"
//#include "math.h"
#include <iostream>
using namespace std;
int f (int * a, int n)
{
int tmp;
int max;
int k;
for(int i=0;i<n;i++)
{ max=a[0];
k=0;
for(int j=0;j<n-i;j++)
if( a[j]>max) {max=a[j];
k=j;}
tmp=a[n-i-1];
a[n-i-1]=a[k];
a[k]=tmp;
}
return 0;
}
void main()
{ int n;
cin>>n;
int* a= new int [n];
for(int i=0;i<n;i++)
cin>>a[i];
f(a,n);
for(int i=0;i<n;i++)
cout<<a[i]<<' ';
delete []a;
}