Number Pairs
Time limit1sMemory limit128 MB
For a given N, list all pairs (X, Y) with X + Y = N where deleting one digit from X yields Y, and count them.
- Level
Medium6 of 10
- Topics
- Math, Brute force, Implementation, String matching
- Solved
- No attempts yet
Problem
Given a natural number , write a program that finds every pair of numbers such that . Here must be a number obtained by deleting exactly one digit from the decimal representation of .
- is a natural number with at least two digits and may not start with .
- has at least one digit; if the deleted digit was the leading one, may start with . Consequently always has exactly one fewer digit than .
For example, deleting the leading digit from gives , and .
Input
The first line contains a natural number . ()
Output
On the first line, print the number of distinct pairs that satisfy the condition.
From the next line, print each valid pair on its own line in increasing order of . Each line has the form X + Y = N, where , , and are replaced by the actual numbers and exactly one space surrounds each + and = sign. Print exactly as it appears after the digit deletion, so it may keep a leading when the deleted digit was the first one.