import java.util.Scanner; /** *只有5和0的卡片能整除90的最大数 **/ public class Main1 { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); int n = scanner.nextInt(); int[] arr=new int[n]; int ret=0; int ret1=0; int sum=0; for (int i = 0; i < arr.length; i++) { arr[i]= scanner.nextInt(); if (arr[i] == 0) { ret++; }else { ret1++; sum=sum+arr[i]; } } if (sum % 9 == 0&&ret!=0) { StringBuilder sb=new StringBuilder(); for (int i = 0; i < ret1; i++) { sb.append(5); } for (int i = 0; i < ret; i++) { sb.append(0); } System.out.println(sb.toString()); }else { int cnt=1; for (int i = 1; i < ret1; i++) { sum=sum-5; if (sum % 9 == 0) { break; } cnt++; } StringBuilder sb=new StringBuilder(); for (int i = 0; i < ret1 - cnt; i++) { sb.append(5); } for (int i = 0; i < ret; i++) { sb.append(0); } if (ret == 0||cnt==ret1) { System.out.println(-1); }else { System.out.println(sb.toString()); } } } }
全部评论
(2) 回帖