#C5052. Find All Pairs with a Given Sum
Find All Pairs with a Given Sum
Find All Pairs with a Given Sum
Given an array of integers and a target integer \(T\), your task is to find all unique pairs \((a, b)\) from the array such that \(a + b = T\). A pair \((a, b)\) is considered unique based on the actual values regardless of order. The output should list the pairs in lexicographical order (i.e. sorted by the first element and then by the second element).
Each pair must be printed on a new line with the two numbers separated by a single space. If no such pair exists, output nothing.
Note: The input is provided via standard input and the output must be produced via standard output.
Example:
Input:
2 7 11 15
9
Output:
2 7
inputFormat
The input consists of two lines:
- The first line contains the array of integers separated by spaces.
- The second line contains the target integer \(T\).
Read input from stdin.
outputFormat
For each pair that sums up to \(T\), print the two integers separated by a space on a new line. The pairs must be sorted in lexicographical order (i.e. sorted by the first element, and in case of a tie, by the second element). If there are no pairs, do not output anything. Write the output to stdout.
## sample2 7 11 15
9
2 7
</p>