Huawei OD computer test-array grouping (C++ & Java & JS & Python)

describe

Input an int type array and ask whether the array can be divided into two groups so that the sum of the elements in the two groups is equal, and all multiples of 5 must be in one group and all multiples of 3 in the other group (not Including multiples of 5), which are not multiples of 5 or multiples of 3, can be placed in any group. The array can be divided into an empty array. If the above conditions are met, true will be output; if not, false will be output.

Data range: The size of each array satisfies 1≤�≤50 1≤n≤50, and the input data size satisfies ∣���∣≤500 ∣val∣≤500 

Enter description:

The first line is the number of data, the second line is the input data

Output description:

Return true or false

Example 1

enter:

4
1 5 -5 1

Output:

true

illustrate:

Group 1: 5 -5 1
Group 2: 1      

Example 2

enter:

3
3 5 8

Output:

false

illustrate:

Since 3 and 5 cannot be placed in the same group, there is no way to divide them.      

Java:

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
    

Guess you like

Origin blog.csdn.net/m0_68036862/article/details/132895232