Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program named hw3_2.cpp (or hw3_2.java) which partitions n positive integers into two disjoint sets with the same sum. Of course, the problem

Write a C++ program named hw3_2.cpp (or hw3_2.java) which partitions n positive integers into two disjoint sets with the same sum. Of course, the problem does not always have a solution.

Input format: This is a sample input from a user.

4

2 3 7 8

The first number (= 4 in the example) indicates that there will be four integer values in the input. Then, all values in the second line (= 2, 3, 7, and 8 in the example) are actual numbers. Thus, your program should read them and present one equal set which includes the smallest number of the input values. Because the input values can have two equal sets of {2, 8} and {3, 7}, your program should display 2 and 8 on the screen. Note that the sum of {2, 8} is 10 and the sum of {3, 7} is also 10. For the problem, you can assume that the max number of input integer values is 15. Also, you can assume that the input values are all distinct.

Sample Run 1: Assume that the user typed the following two lines

4

2 3 7 8

This is the correct output of your program.

Equal Set: 2 8

Note that the sequence of output values is important. Your program has to display the set with the smallest value in the input. So, the correct set is {2, 8}. For the set, your program should display it in the ascending order. Thus, the correct answer is 2 and then 8.

Sample Run 2: Assume that the user typed the following two lines

3

7 5 1

This is the correct output of your program.

Equal Set: 0

Since it is not possible to have two equal sets from the input, your program should display just 0 on the screen.

Sample Run 3: Assume that the user typed the following two lines

6

3 5 20 7 1 14

This is the correct output of your program.

Equal Set: 1 3 7 14

Sample Run 4: Assume that the user typed the following two lines

5

10 8 6 4 2

This is the correct output of your program.

Equal Set: 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions