Cod sursa(job #109449)
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
long i, o, aux, m, vb1;
int v[100010];
char ch, z;
int cmp (const void * a, const void * b) {
return ( *(int*)a - *(int*)b );
}
int main() {
freopen("ordine.in", "r", stdin);
freopen("ordine.out", "w", stdout);
while (scanf("%c", &ch) == 1) {
v[++o] = (long)(ch) - 96;
}
qsort(v, o + 1, sizeof(int), cmp);
/*for (i = 1;i <= o; ++i) {
printf("%d ", v[i]);
}*/
vb1 = 1;
while (vb1 == 1) {
vb1 = 0;
for (i = 2;i <= o; ++i) {
if (v[i] == v[i - 1]) {
aux = i + 1;
while (v[i] == v[aux] && aux < o) {
++aux;
}
if (v[i] != v[aux] && aux <= o) {
m = v[i];
v[i] = v[aux];
v[aux] = m;
} else {
aux = i - 1;
while (v[i] == v[aux] && aux > 1) {
--aux;
}
m = v[i];
v[i] = v[aux];
v[aux] = m;
}
vb1 = 1;
}
}
}
for (i = 1;i <= o; ++i) {
z = (char)(v[i] + 96);
printf("%c", z);
}
return 0;
}