include stdafx include math include iostream using namespace std int n

 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
45
46
47
48
49
50
51
52
#include "stdafx.h"
#include "math.h"
#include <iostream>
using namespace std;
int n; // n-число символов в строке
int f (char* a,char *b)
{
int * fam = new int [n];
for (int i=0;i<n;i++) fam[i]=0;
char tmp=a[0];
char min=a[0], max= a[0];
int j=-1;
int k;
for (int i=0;i<n;i++)
if(a[i]>max) max=a[i];
for (int i=0;i<n;i++)
if(a[i]<tmp) {tmp=a[i];
k=i;
}
fam[k]=1;
b[++j]=tmp;
for (int i=0;i<n-1;i++)
{ tmp=max;
for (int l=0;l<n;l++)
{
if((a[l]<tmp) && (b[j-1]<=a[l]) && !fam[l]) {tmp=a[l];
k=l;}
}
b[++j]=tmp;
fam[k]=1;
}
return 0;
}
void main()
{
cin>>n;
char* a= new char [n];
char* b= new char [n];
for (int i=0;i<n;i++) cin>>a[i];
f(a,b);
for (int i=0;i<n;i++) cout<<b[i];
}