Finding matching pairs
Time limit2sMemory limit512 MB
Given 2 to 10 integers and a target, print every position pair that sums to the target in lexicographic order, then the count.
- Level
Easy3 of 10
- Topics
- Sorting, Brute force, Implementation
- Solved
- No attempts yet
Problem
The first line holds several integers and the second line holds one target value. Print every pair of numbers that sit at two different positions and sum to the target value, then print the number of such pairs on the last line.
Input
The first line has 2 to 10 integers separated by spaces. The second line has one integer, the target value. Every integer given is a natural number not greater than 100,000.
Output
Print one pair per line, then print the number of pairs on the last line.
Print a pair as and in that order on one line, with . The pairs and have the same composition and count as one pair.
Pairs are counted by position. Print one line for each choice of two different positions that meets the condition, and count each choice separately even when an identical pair of values was already printed. For the input 1 1 2 with target value , print on two lines and print the count .
When several pairs exist, print them in lexicographic order. comes before when , or when and .
When no pair meets the condition, print only the count .