← Back to STL Containers
Question 476
Set Algebra From Input
Set Algebra From Input
Read two lines from standard input. The first line holds the integers of set A and the second line the integers of set B, separated by spaces. A line may repeat a value, and every line contains at least one integer. Then print exactly three lines, in this order: 1. The labelUnion:followed by every value that is in A or B (or both), ascending. 2. The labelIntersection:followed by every value that is in both A and B, ascending. 3. The labelA only:followed by every value that is in A but not in B, ascending. Each label is followed by one space, then the values separated by single spaces (a trailing space after the last value is fine). If a result has no values, print(none)in place of the values, for exampleA only: (none). Example input: 1 2 3 2 3 4 The output for that input is shown in Expected Output.
Expected Output:
Union: 1 2 3 4 Intersection: 2 3 A only: 1 Union: 5 6 Intersection: 5 6 A only: (none) Union: 1 4 9 Intersection: (none) A only: 1 4
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
STL ContainersSets
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.