Hello World!
Time limit1sMemory limit32 MB
Assign distinct digits to the seven letters in hello + world so the sum equals N, then print the smallest hello in a column format.
- Level
Medium4 of 10
- Topics
- Brute force, Math, Implementation
- Solved
- No attempts yet
Problem
You are given a positive integer . Assign one digit to each of the seven letters d, e, h, l, o, r, w so that the addition below holds.
Here hello is the five digit number whose digits from the most significant one are h, e, l, l, o, and world is the five digit number whose digits from the most significant one are w, o, r, l, d. The digits assigned to the seven letters are pairwise different, and the leading digits h and w cannot be 0.
Input
The first line contains a positive integer . fits in the range of a 32 bit signed integer.
Output
If no assignment satisfies the equation, print No Answer.
Otherwise take the assignment whose hello is smallest and print four lines. Let be the number of digits of and let .
- On the first line print hello right aligned in a field of width .
- On the second line print
+, then world right aligned in a field of width . - On the third line print the character
-exactly times. - On the fourth line print right aligned in a field of width .
Right aligned means the number is padded on the left with spaces until it reaches the given width.