B

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.

Examples
Input
automaton
tomat
Output
automaton
Input
array
arary
Output
array
Input
both
hot
Output
both
Input
need
tree
Output
need tree
Note
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”.

题意:输入两个串,则
(1)字母相同,顺序相同,输出automaton
(2)字母相同,顺序不同,个数相同, 输出array
(3)字母相同,顺序不同,个数不同,输出both
(4)字母不同,输出need tree

#include <bits/stdc++.h>

using namespace std;

int main()
{
    char str1[1005],str2[1005];
    int num1[105],num2[105];
    memset(num1,0,sizeof(num1));
    memset(num2,0,sizeof(num2));
    scanf("%s%s",str1,str2);
    int len1 = strlen(str1);
    int len2 = strlen(str2);
    for(int i = 0;i < len1;i++)
    {
        num1[str1[i] - 'a']++;
    }
    for(int i = 0 ;i < len2;i++)
    {
        num2[str2[i] - 'a']++;
    }
    int i,j;
    for(i = 0;i < 26;i++)
    {
        if(num1[i] < num2[i])
            break;
    }
    if(i < 26)//判断是否有不相等的部分
    {
        printf("need tree
");//字母不同
    }
    else
    {
        for(i = j = 0;i < len2 && j < len1;i++,j++)
        {
            while(j < len1 && str1[j] != str2[i])
            {
                j++;
            }
        }
        if(i < len2 && len1 == len2)//字母相同,个数相等
        {
            printf("array
");
        }
        else if(i < len2&& len1 > len2)
        {
            printf("both
");//字母相同,个数不等
        }
        else if(i >= len2)//正常退出循环,代表字母顺序相等
        {
            printf("automaton
");
        }
    }
    return 0;
}

原文地址:https://www.cnblogs.com/tomjobs/p/10612579.html