import java util Scanner import java lang Math public class MaxNum pub

  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
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
import java.util.Scanner;
import java.lang.Math;
public class MaxNum {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int size=sc.nextInt(),i,j,k,temp,a,b,c;
int [] NumbMas=new int [size];
int [] raz=new int [size];
for (i=0;i<size;i++)
{
NumbMas[i]=sc.nextInt();
temp=NumbMas[i];
while(temp>0)
{
temp=temp/10;
raz[i]++;
}
}
for (i=size-1;i>0;i--)
{
for (j=0;j<i;j++)
{
for (k=0;k<=raz[j] & k<=raz[j+1];k++)
{
a=(int)(NumbMas[j]/Math.pow(10,raz[j]-(k+1)))%10;
b=(int)(NumbMas[j+1]/Math.pow(10,raz[j+1]-(k+1)))%10;
if ((k==raz[j] | k==raz[j+1] )) {
if (raz[j] == 1 & (a < b)) {
temp = NumbMas[j];
NumbMas[j] = NumbMas[j + 1];
NumbMas[j + 1] = temp;
temp = raz[j];
raz[j] = raz[j + 1];
raz[j + 1] = temp;
break;
} else if (raz[j] > raz[j + 1]) {
for (c = 1; c <= (raz[j] - raz[j + 1]); c++) {
if ((int) (NumbMas[j] / Math.pow(10, raz[j] - (c))) % 10 < (int) (NumbMas[j] / Math.pow(10, (raz[j] - raz[j + 1]) - c)) % 10)
break;
else {
temp = NumbMas[j];
NumbMas[j] = NumbMas[j + 1];
NumbMas[j + 1] = temp;
temp = raz[j];
raz[j] = raz[j + 1];
raz[j + 1] = temp;
break;
}
}
} else if (raz[j + 1] > raz[j]) {
for (c = 1; c <= (raz[j + 1] - raz[j]); c++) {
if ((int) (NumbMas[j + 1] / Math.pow(10, raz[j + 1] - (c))) % 10 > (int) (NumbMas[j + 1] / Math.pow(10, (raz[j + 1] - raz[j]) - c)) % 10)
break;
else {
temp = NumbMas[j];
NumbMas[j] = NumbMas[j + 1];
NumbMas[j + 1] = temp;
temp = raz[j];
raz[j] = raz[j + 1];
raz[j + 1] = temp;
break;
}
}
}
}
if(a<b & !(k==raz[j] | k==raz[j+1]))
{
temp=NumbMas[j];
NumbMas[j]=NumbMas[j+1];
NumbMas[j+1]=temp;
temp=raz[j];
raz[j]=raz[j+1];
raz[j+1]=temp;
break;
}
if (a>b)
break;
}
}
}
for (i=0;i<size-1;i++)
{
if (NumbMas[i]==0)
{
temp=NumbMas[i];
NumbMas[i]=NumbMas[i+1];
NumbMas[i+1]=temp;
temp=raz[i];
raz[i]=raz[i+1];
raz[i+1]=temp;
}
}
for (i=0;i<size;i++)
{
System.out.print(NumbMas[i]);
}
}
}