#650. Train and Peter (火车和彼得)
Train and Peter (火车和彼得)
问题描述(翻译)
彼得喜欢乘火车旅行。他非常喜欢它,以至于在火车上他睡着了。
有一次夏天,彼得乘火车从A市到B市,像往常一样,他正在睡觉。然后他醒来,开始透过窗户看,注意到每个火车站都有一面特定颜色的旗帜。
在车站,他告诉父母他在做什么,并分别写了他在睡觉前和睡后看到的两串颜色。
彼得的父母知道他们的儿子喜欢幻想。他们给你火车从A到B的路上依次经过的车站的旗帜颜色列表,并要求你找出彼得是否能在从A到B或从B到A的路上看到这些序列。
彼得的父母用小写的拉丁字母作为颜色。同一个字母代表相同的颜色,不同的字母——代表不同的颜色。
输入数据包含三行。第一行包含一个非空字符串,其长度不超过 105,字符串由小写拉丁字母组成——从 A 到 B 途中车站的旗帜颜色。在从B到A的途中,火车经过相同的车站,但顺序相反。
第二行包含彼得在第一个清醒时期写的序列。第三行包含序列,写在第二个清醒时期。这两个序列都是非空的,由小写拉丁字母组成,每个序列的长度不超过 100 个字母。每个序列都按时间顺序编写。
-
输出四个单词之一,不带引号:
- "forward"— (前进) 如果彼得只能在从 A 到 B 的路上看到这样的序列;
- “backward” — (向后) 如果彼得在从 B 到 A 的路上能看到这样的序列;
- “both” — (两者) 如果彼得能在从 A 到 B 的路上和从 B 到 A 的路上看到这样的序列;
- “fantasy” — (幻想) 如果彼得看不到这样的序列。
输入
输入数据包含三行。第一行包含一个非空字符串,其长度不超过 105,字符串由小写拉丁字母组成——从 A 到 B 途中车站的旗帜颜色。在从B到A的途中,火车经过相同的车站,但顺序相反。
第二行包含彼得在第一个清醒时期写的序列。第三行包含序列,写在第二个清醒时期。这两个序列都是非空的,由小写拉丁字母组成,每个序列的长度不超过 100 个字母。每个序列都按时间顺序编写。
输出
输出四个单词之一,不带引号:
- "forward"— (前进) 如果彼得只能在从 A 到 B 的路上看到这样的序列;
- “backward” — (向后)如果彼得在从 B 到 A 的路上能看到这样的序列;
- “both” — (两者)如果彼得能在从 A 到 B 的路上和从 B 到 A 的路上看到这样的序列;
- “fantasy” - (幻想)如果彼得看不到这样的序列。
备注
假设火车一直在移动,所以一面旗帜不能看到两次。车站 A 和 B 没有旗帜。
题目原文
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.
At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.
Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.
Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours.
The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order.
Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B;
- «backward» — if Peter could see such sequences on the way from B to A;
- «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A;
- «fantasy» — if Peter could not see such sequences.
Input
The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order.
Output
Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B;
- «backward» — if Peter could see such sequences on the way from B to A;
- «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A;
- «fantasy» — if Peter could not see such sequences.
Samples
atob
a
b
forward
aaacaaa
aca
aa
both
Note
It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B.