Palindrome
Time limit1sMemory limit1024 MB
Given four integers from 1 to 9, decide whether changing at most one element makes the sequence a palindrome, and print one such palindrome or EI.
- Level
Easy2 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Problem
A sequence is called a palindrome if it reads the same forwards and backwards. For example, the sequence 1, 2, 2, 1 is a palindrome because it reads 1, 2, 2, 1 in reverse. The sequence 1, 2, 3, 4 is not a palindrome because it reads 4, 3, 2, 1 in reverse.
Write a program that checks whether a sequence of four integers can become a palindrome when at most one of its elements is changed.
Input
A single line contains four integers from , separated by spaces.
Output
If the input sequence is already a palindrome, or can be made into one by changing one element, print JAH on the first line and, on the second line, four integers separated by spaces: the resulting palindrome. If several palindromes are possible, print any one of them.
If the sequence cannot be made into a palindrome by changing at most one element, print only EI on a single line.
Note: the output must contain nothing else. It is either JAH followed by exactly four integers, or EI and nothing more.