2022.1.23
题目网址:
https://acs.jxnu.edu.cn/problem/CF8A
原题:
Train and Peter
1000ms 65536K
描述:
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市看到的顺序。
请记得,彼得醒来了两次。
彼得的父母用小写拉丁字母来表示颜色。相同的字母代表相同的颜色,不同的字母代表不同的颜色。
输入:
输入数据包括三行。第一行包含一个非空字符串,这个字符串的长度不超过105,这个字符串由小写拉丁字母组成---代表从A市到B市站台上旗帜的颜色。从B到A火车经过相同的站台,但是是相反的次序。
第二行包含了一个次序,是彼得在第一次醒来写下的。第三行包含一个次序,是彼得在第二次醒来写下的。两个次序都是非空的,都由小写拉丁字母组成,每个次序的长度都不超过100。每个次序都是按时间顺序写下的。
输出:
输出以下4个单词之一,不带引号。
《前》---如果彼得只是在从A到B 的途中看到这样的次序;
《后》---如果彼得从B到A的途中看到这个次序;
《两个都》--如果彼得是从A到B和B到A的途中看到这样的次序;
《想象》---如果彼得没有看到过这样的次序;
注释:
我们认为这列火车一直在移动,所以一个旗帜不能被看见两次。A站和B站没有旗帜。