import java util stream IntStream import java util Scanner import java

 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
import java.util.stream.IntStream;
import java.util.Scanner;
import java.lang.Math;
public class Factorial {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int size=sc.nextInt(),i,j,k,temp;
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++)
{
if((NumbMas[j]/Math.pow(10,raz[j]-(k+1)))%10<(NumbMas[j+1]/Math.pow(10,raz[j+1]-(k+1)))%10)
{
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 ((NumbMas[j]/Math.pow(10,raz[j]-(k+1)))%10==(NumbMas[j+1]/Math.pow(10,raz[j+1]-(k+1)))%10)
continue;
else if ((NumbMas[j]/Math.pow(10,raz[j]-(k+1)))%10>(NumbMas[j+1]/Math.pow(10,raz[j+1]-(k+1)))%10)
break;
}
}
}
for (i=0;i<size;i++)
{
System.out.print(NumbMas[i]);
System.out.print(" ");
System.out.println(raz[i]);
}
}
}