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到B 的途中看到这些序列。请记住,彼得有两次清醒的时期。
彼得的父母用小写拉丁字母表示颜色。相同的字母代表相同的颜色,不同的字母代表不同的颜色。
感谢Macw提供翻译
输入格式
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
,如果彼得可以在A到B的途中看到序列。 - 输出
both
,如果同时满足条件1和条件2。 - 输出
fantasy
,如果同时不满足条件1、2和3。
输入输出样例
输入#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.
对于100%的数据,保证输入字符串有且只包含拉丁小写字符。
补充说明:列车一直都在移动,所以一面同样的旗子不可能被看到两次。
请注意,本题空间限制为64MB,是默认空间限制的二分之一