CF8A.Train and Peter
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
彼得喜欢乘坐火车旅行。他非常喜欢坐火车,以至于在火车上常常睡着。
去年夏天,彼得曾乘火车从城市 A 前往城市 B,和往常一样,他在途中睡着了。后来他醒了过来,开始透过车窗向外张望,发现每个铁路车站都悬挂着一面特定颜色的旗帜。
男孩开始记忆自己所见到的旗帜颜色的顺序。但不久后他又一次睡着了。不幸的是,这次他并未睡太久;他再次醒来,继续记忆所见的颜色;接着他又一次睡着了,并且这一次一直睡到旅程结束。
到达车站后,他向父母讲述了自己在旅途中的所作所为,并写下了两段颜色序列:一段是他第一次睡着前看到的颜色序列,另一段则是他第二次睡着前(即第二次醒来后、最终入睡之前)看到的颜色序列。
彼得的父母知道自己的儿子喜欢幻想。他们向你提供了火车从 A 到 B 的途中依次经过的所有车站的旗帜颜色列表,并请你判断:彼得所写的这两段序列,是否可能分别出现在从 A 到 B 的途中,或从 B 到 A 的途中。请注意:彼得共有两次清醒时段。
彼得的父母用小写拉丁字母表示颜色。相同字母代表相同颜色,不同字母代表不同颜色。
输入格式
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.
输入数据包含三行。第一行包含一个非空字符串,其长度不超过 105,该字符串由小写拉丁字母组成——表示从 A 到 B 的途中各车站的旗帜颜色。从 B 返回 A 时,列车经过相同的车站,但顺序相反。
第二行包含彼得在第一次清醒期间所记录的序列。第三行包含他在第二次清醒期间所记录的序列。这两个序列均非空,均由小写拉丁字母组成,且每个序列的长度均不超过 100 个字母。每个序列均按时间顺序书写。
输出格式
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.
输出以下四个单词之一(不带引号):
- «forward» — 如果彼得只能在从 A 到 B 的途中看到这样的序列;
- «backward» — 如果彼得只能在从 B 到 A 的途中看到这样的序列;
- «both» — 如果彼得在从 A 到 B 以及从 B 到 A 的途中都能看到这样的序列;
- «fantasy» — 如果彼得无法看到这样的序列。
输入输出样例
输入#1
atob a b
输出#1
forward
输入#2
aaacaaa aca aa
输出#2
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 站均没有旗帜。
输入解题思路,AI测评打分。不知道怎么写?