printРабочее место участника

printЗадачи

1364. Palinwords

Ограничения: время – 1s/2s, память – 64MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод copy
Послать решение Blockly Посылки Темы Где Обсудить (0)

A palindrome is a string of characters which can be read forward and backward and still result in the same word, e.g. "mumdadmum". So by definition the empty string, all strings containing 1 character, and all strings containing 2 equal characters are palindromes. The length of a palindrome is the number of characters in the palindrome.
A palinword is a string of characters that contains at least 2 different palindromes each with a length of at least 3. (Here the position is immaterial: the same palindrome occurring in another position is not considered as different.) Neither of these 2 palindromes may be embedded in the other palindrome (for example the palindrome "mum" is embedded in the palindrome "amuma", and "aaa" is embedded in "aaaa") but they may partially overlap. Also see the examples below.
Your program's task is to copy only the palinwords from the input file to the output file.
The input for your program is a textfile. Each line in this file is empty or consists of one or more words (uppercase letters 'A' through 'Z' only) separated by one or more spaces (each line in the input file contains at most 255 characters in all).
The output file is a textfile and must have one palinword per line in order of occurrence in the input file.

Sample Input

MOEILIJKHEDEN INVOER
VERNEDEREN
AMUMA AMAMA MUMMUM
AMATRAMA AAAA ABATRABAR
DUMMY WORDS

Sample Output

MOEILIJKHEDEN
VERNEDEREN
AMAMA
MUMMUM
Source: UVA 257
loading