-
Notifications
You must be signed in to change notification settings - Fork 0
/
aa.java
46 lines (37 loc) · 1.25 KB
/
aa.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
import javax.swing.plaf.basic.BasicButtonUI;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class aa {
public static void main(String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
boolean tf = false;
for (int i=0; i<s.length(); i++){
if (s.charAt(i)=='0'){
tf = true;
break;
}
}
if (tf==false) System.out.println(-1);
else{
int sum =0;
for (int i=0; i<s.length(); i++)
sum += Integer.parseInt(s.substring(i, i + 1));
if (sum%3!=0) System.out.println(-1);
else{
int[] array = new int[s.length()];
for (int i = 0;i <array.length; i++){
array[i] = Integer.parseInt(s.substring(i,i+1));
}
Arrays.sort(array);
StringBuilder sb = new StringBuilder("");
for (int i=array.length-1; i>=0; i--){
sb.append(array[i]);
}
System.out.println(sb);
}
}
}
}