#include<iostream>
using namespace std;
int Ordonare( int a[100] , int n , int k)
{
int i;
int j;
int aux = 0;
for ( i = 1 ; i < k ; i++ )
for ( j = i + 1; j <= k; j++ )
if ( a[i] > a[j] )
{
aux = a[i];
a[i] = a[j];
a[j] = aux;
}
for ( i = k + 1 ; i < n ; i++ )
for ( j = i + 1 ; j <= n ; j++ )
if ( a[i] < a[j] )
{
aux = a[i];
a[i] = a[j];
a[j] = aux;
}
}
int main ()
{
int a[100];
int n;
int k;
cin >> n;
cin >> k;
for ( int i = 1 ; i <= n ; i++ )
cin >> a[i];
Ordonare( a , n , k );
for ( int i = 1; i <= n; i++ )
cout<< a[i] << ' ';
system("pause");
return 0;
}
|