Describe |
Write a function, passing in an array of int, to return whether the array can be divided into two groups, so that the elements in the two groups are added together and equal, and that all multiples of 5 must be in one group, and all multiples of 3 in another group (not including a multiple of 5), can satisfy the above conditions, return True ; returns false when not satisfied. |
Knowledge points |
strings, loops, functions, pointers, enumerations, bitwise operations, structs, unions, file operations, recursion |
Run time limit |
10M |
Memory limit |
128 |
Input |
Enter the number of data entered Enter an array of type int |
Output |
Returns TRUE or False |
Sample input |
4 1 5-5 1 |
Sample output |
True |
Package Com.oj5;import Java.util.map;import Java.util.scanner;import Java.util.treemap;public class Main {public Stati c void Main (string[] args) {Scanner in = new Scanner (system.in); int num = In.nextint (); int[] data = new Int[num]; int[] flag = new Int[num]; for (int i = 0;i < num; i++) data[i] = In.nextint (); Findplan (data,flag,num,0); if (stop==true) System.out.println ("true"); Else System.out.println ("false"); } static Boolean stop = False;private static void Findplan (int[] data, int[] flag, int num, int pos) {if (pos==num) {//sy Stem.out.println ("Hello"); int sumleft = 0,sumright = 0;int i;for (i = 0;i < num; i++) if (data[i]%5==0&&flag[i]== 0| | flag[i]==0&&data[i]%5!=0&&data[i]%3!=0) Sumleft + = Data[i];else if (data[i]%3==0&&data[i]%5 !=0&&flag[i]==1| | flag[i]==1&&data[i]%5!=0&&data[i]%3!=0) Sumright + = Data[i];elsebreak;if (i==num&&sumleft= =sumright) stop = True;return;} Flag[pos] = 0;findplan (data,flag,num,pos+1); Flag[pos] = 1;findplan (data,flag,num,pos+1);}}
201301 Java topic level 0-1