| Describe |
Write a function, pass in an int array, returns whether the array can be divided into two groups, so that the elements of the two groups are combined and equal, and that all multiples of 5 must be in one group, all multiples of 3 in another group (excluding a multiple of 5), which satisfies the above conditions and returns true , false when not satisfied.
|
| Knowledge points |
strings, loops, functions, pointers, enumerations, bitwise operations, structures, associations, file operations, recursion |
| Run time limit |
10M |
| Memory Limits |
128 |
| Input |
Enter the number of data entered Enter an array of int
|
| Output |
Returns TRUE or False
|
| Sample input |
4 1 5-5 1 |
| Sample output |
True |
Import java.util.ArrayList;
Import Java.util.Scanner;
public class main{public static void Main (string[] args) {Scanner Scanner = new Scanner (system.in);
int length = Scanner.nextint ();
int[] numbers = new Int[length];
for (int i = 0; i < length; i++) {Numbers[i] = Scanner.nextint ();
System.out.print (Result (numbers));
Scanner.close (); private static Boolean result (int[] numbers) {int numMultiple5 = 0; The number of all multiples of 5 and int numMultiple3 = 0; The number of all multiples of 3 and arraylist<integer> ArrayList = new arraylist<integer> (); The number of stores that are not multiples of 3 and 5 for (int i = 0; i < numbers.length i++) {if (Numbers[i]% 5 = 0) NumMultiple5 + = Numbers[i] ; All multiples of 5 add else if (Numbers[i]% 3 = 0 && numMultiple5% 5!= 0) NumMultiple3 + = Numbers[i]; The multiples of all 3 are added else Arraylist.add (Numbers[i]);
Storage is not multiples of 3 and 5}//Definition J, used as the number of pointers to traverse ArrayList int j = 0;
boolean bool = Check (NumMultiple3, NumMultiple5, ArrayList, J);
return bool;
} private static Boolean check (int sum3, int sum5, arraylist<integer> list, int j) {if (J >= list.size ())/
/When J is greater than list.size (), indicating that the list has already traversed the return sum3 = = SUM5; else {//traversal, which will not be multiples of 3 and 5, added to the previously stored numMultiple3 and numMultiple5, returns the result of the final addition comparison return check (Sum3 + list.get (j), SUM5, list, J + 1) | |
Check (sum3, SUM5 + list.get (j), List, J + 1);
}
}
}