201301 Java topic level 0-1

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.