#K62442. Unique Pair Finder
Unique Pair Finder
Unique Pair Finder
You are given a list of integers and a target integer. Your task is to find all unique pairs of numbers in the list that sum exactly to the target. Each unique pair should be printed once in the format (a, b)
where a
and b
are the two numbers (with the smaller number first if they are different).
Note: The order of the pairs in the output should be in ascending lexicographical order. If there are no pairs that sum to the target, output nothing.
Example:
Input: 5 1 2 3 4 3 6</p>Output: (2, 4) (3, 3)
inputFormat
The input is given via stdin and consists of three lines:
- The first line contains an integer n, representing the number of elements in the array.
- The second line contains n integers separated by spaces.
- The third line contains an integer which is the target sum.
outputFormat
Print each unique pair that sums to the target on a separate line in the format (a, b)
. Pairs must be printed in ascending lexicographical order. If no valid pair exists, output nothing.
5
1 2 3 4 3
6
(2, 4)
(3, 3)
</p>