Train and Peter
题目(https://acs.jxnu.edu.cn/problem/CF8A)描述:
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.
样例输入:
atob
a
b
样例输出:
forward
样例输入:
aaacaaa
aca
aa
样例输出:
both
注释:
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.
翻译:
皮特喜欢通过火车去旅行。他太喜欢了以至于他在火车上睡着了。
在一个夏天,皮特在做火车从A市去B市的途中睡着了。他醒来以后,开始看窗外的风景,发现每个火车站都有一面纯色的旗帜。
他开始按他看到旗子的顺序去记忆旗子的颜色。但是不久他又睡着了。不幸的是,他没有睡太久,他醒来又继续记忆旗子的颜色。然后他又又睡着了,直接睡到目的地。
在车站他告诉他父母他在火车上做的事,并且写下了他记忆两次旗子颜色的序列。
父母知道他们的孩子喜欢幻想。他们告诉你从A到B路线上的车站旁的旗子的颜色的序列,并且问你皮特从A到B或从B到A是否能够看到这些序列。注意皮特在路上已经经记录了两段颜色序列。
皮特的父母用小写字母表示旗子的颜色。相同的字母表示相同的颜色,不同的字母表示不同的颜色。
输入:
输入数据有三行。第一行包含一个没有空格的序列,长度不超过100000,表示从A市到B市的车站旁的旗子的颜色序列。从B市到A市经过相同的车站,不过顺序要倒转。
第二行为皮特第一次记录旗子的颜色序列。第三行为皮特第二次记录旗子的颜色序列。两段序列都没有空格,且长度不超过100。颜色按看到的时间先后排序。
输出:
输出四个不带书名号的单词之一:
?forward? —如果皮特只能从A到B的路上看到这样的序列。
?backward? — 如果皮特只能从B到A的路上看到这样的序列。
?both? — 如果皮特能从A到B和B到A的路上看到这样的序列。
?fantasy? — 如果皮特不能看到这段序列。
样例输入:
atob
a
b
样例输出:
forward
样例输入:
aaacaaa
aca
aa
样例输出:
both
注释:
假设火车一刻不停的行驶,一面旗帜只能看见一次。在车站A和B没有旗帜。