Description

Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.

At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), s and t. You need to transform word s into word t". The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more.

Bizon the Champion wonders whether the "Bizons" can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any order.

Input

The first line contains a non-empty word s. The second line contains a non-empty word t. Words s and t are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters.

Output

In the single line print the answer to the problem. Print "need tree" (without the quotes) if word s cannot be transformed into word t even with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without the quotes) if you need only the suffix array to solve the problem. Print "both" (without the quotes), if you need both data structures to solve the problem.

It's guaranteed that if you can solve the problem only with use of suffix array, then it is impossible to solve it only with use of suffix automaton. This is also true for suffix automaton.

Sample Input

Input
automaton
tomat
Output
automaton
Input
array
arary
Output
array
Input
both
hot
Output
both
Input
need
tree
Output
need tree

Hint

In the third sample you can act like that: first transform "both" into "oth" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get "hot".

#include <iostream>
#include <cstring>
using namespace std; int main()
{
char s[],t[];
int as[],at[],flag;
while(cin>>s>>t)
{
flag=;
memset(as,,sizeof(as));
memset(at,,sizeof(at));
int lens,lent;
lens=strlen(s);
lent=strlen(t);
for(int i=;i<lens;i++)
as[s[i]-'a']++;
for(int i=;i<lent;i++)
at[t[i]-'a']++;
for(int i=;i<;i++)
if(as[i]>=at[i])
continue;
else {flag=; break; }
if(flag==)
{
if(lens==lent)
cout<<"array"<<endl;
else
{
int r=;
for(int i=,j=;i<lens;i++)
{
if(s[i]==t[j])
j++;
if(j==lent)
{
r=;break;
}
}
if(r) cout<<"automaton"<<endl;
else cout<<"both"<<endl;
}
}
else
{
cout<<"need tree"<<endl;
}
}
return ;
}
#include <iostream>
#include <cstring>
using namespace std; int main()
{
char s[],t[];
int as[],at[],flag;
while(cin>>s>>t)
{
flag=;
memset(as,,sizeof(as));
memset(at,,sizeof(at));
int lens,lent;
lens=strlen(s);
lent=strlen(t);
for(int i=;i<lens;i++)
as[s[i]-'a']++;
for(int i=;i<lent;i++)
at[t[i]-'a']++;
for(int i=;i<;i++)
if(as[i]>=at[i])
continue;
else {flag=; break; }
if(flag==)
{
if(lens==lent)
cout<<"array"<<endl;
else
{
int r=;
for(int i=,j=;i<lens;i++)
{
if(s[i]==t[j])
j++;
if(j==lent)
{
r=;break;
}
}
if(r) cout<<"automaton"<<endl;
else cout<<"both"<<endl;
}
}
else
{
cout<<"need tree"<<endl;
}
}
return ;
}

Codeforces Round #256 (Div. 2) B Suffix Structures的更多相关文章

  1. Codeforces Round #256 (Div. 2) B. Suffix Structures(模拟)

    题目链接:http://codeforces.com/contest/448/problem/B --------------------------------------------------- ...

  2. Codeforces Round #256 (Div. 2/B)/Codeforces448B_Suffix Structures(字符串处理)

    解题报告 四种情况相应以下四组数据. 给两字符串,推断第一个字符串是怎么变到第二个字符串. automaton 去掉随意字符后成功转换 array 改变随意两字符后成功转换 再者是两个都有和两个都没有 ...

  3. Codeforces Round #256 (Div. 2) 题解

    Problem A: A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standar ...

  4. Codeforces Round #256 (Div. 2)

    A - Rewards 水题,把a累加,然后向上取整(double)a/5,把b累加,然后向上取整(double)b/10,然后判断a+b是不是大于n即可 #include <iostream& ...

  5. Codeforces Round #256 (Div. 2) B

    B. Suffix Structures Bizon the Champion isn't just a bison. He also is a favorite of the "Bizon ...

  6. Codeforces Round #256 (Div. 2) B (448B) Suffix Structures

    题意就是将第一个字符串转化为第二个字符串,支持两个操作.一个是删除,一个是更换字符位置. 简单的字符串操作!. AC代码例如以下: #include<iostream> #include& ...

  7. Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)

    转载请注明出处:viewmode=contents" target="_blank">http://blog.csdn.net/u012860063?viewmod ...

  8. Codeforces Round #256 (Div. 2) A. Rewards

    A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  9. Codeforces Round #256 (Div. 2) D. Multiplication Table 二分法

     D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes input st ...

随机推荐

  1. shell实现四则运算简单方法

    在刚刚学习写shell 批处理时候,进行逻辑运算中,少不了需要进行基础的:四则运算,这里说说在linux shell 里面简单的实现方法.1.简单方法$ b=$((5*5+5-3/2)) $ echo ...

  2. 改造jQuery-Tagit 插件支持中文全角的逗号和空格

    jQuery 的 tagit 插件效果还是不错的,今天用到该插件但发现不能自定义标签分隔符,只能是英文半角逗号或空格,于是想改造下 效果: 先研究了一番插件的代码,发现并不能通过插件自身的扩展方法来实 ...

  3. layer ifram 弹出框

    父层 <div class="col-xs-4 text-left" style="padding-left: 50px;"><button ...

  4. css3-文字旋转

    <meta charset="utf-8"/><style> * {margin: 0; padding: 0;} ul { height: 80px; b ...

  5. 【锋利的Jquery】读书笔记二

    一.jquery选择器 基本选择器 层次选择器 过滤选择器 基本过滤 内容过滤 可见性过滤 属性过滤 子元素过滤 first  : 获取单个元素       $("div:first&quo ...

  6. Chapter 17_3 table的默认值

    对象属性 有很多情况需要把有些属性绑定到某个对象,例如:函数与其名称.table的默认值.数组大小等... 当对象是一个table时,可以通过适当的key将属性存储在这个table中. 如果对象不是一 ...

  7. SAP HANA studio 创建分析视图

    [Step By Step]SAP HANA中创建分析视图(Analytic View) 1. 在Modeler视图中点击新建Analytic View 2. 设置分析视图的属性 Name: 分析视图 ...

  8. @classmethod及@staticmethod方法浅析【python】

    目前对于python中@classmethod 类方法和@staticmethod静态方法的有了一定的认识,之后有进一步的认识后继续记录. @classmethod :是和一个class类相关的方法, ...

  9. VFL语言

    VFL语言 VFL即Visual Format Language,可视化格式语言 NSDictionaryOfVariableBindings(testViewA, testViewB):此为一个宏, ...

  10. java 用hmac-sha1进行签名

    public static String getSignature(String s) throws NoSuchAlgorithmException, UnsupportedEncodingExce ...