题解 | #数组分组#
数组分组
https://www.nowcoder.com/practice/9af744a3517440508dbeb297020aca86
import java.util.*; public class Main { public static void main(String[] args) { Scanner fzhinput = new Scanner(System.in); int num = fzhinput.nextInt(); int x; int sz1[] = new int[num]; int sz2[] = new int[num]; int sz3[] = new int[num]; int n = 0, m = 0, l = 0, sum1 = 0, sum2 = 0; for (int i = 0; i < num; i++) { x = fzhinput.nextInt(); if (x % 5 == 0) { sz1[n] = x; n++; } else if (x % 3 == 0 && x % 5 != 0) { sz2[m] = x; m++; } else { sz3[l] = x; l++; } } for (int i = 0; i < m; i++) { sum2 += sz2[i]; } for (int i = 0; i < n; i++) { sum1 += sz1[i]; } boolean pd = sz3jr(sum1,sum2,sz3,l,0); System.out.println(pd); } private static boolean sz3jr(int sum1,int sum2,int sz3[],int l,int i){ if(i==l){ return sum1==sum2; } return sz3jr(sum1,sum2+sz3[i],sz3,l,i+1)||sz3jr(sum1+sz3[i],sum2,sz3,l,i+1); } }