天天看點

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

#include <iostream>
#include <string>

using namespace std;

bool bothmethods(string s, string t) 
{
	int a[505] = {};
	for (int i = 0; i < s.size(); ++i) {
		++a[s[i]];
	}
	for (int i = 0; i < t.size(); ++i) {
		--a[t[i]];
	}
	for (int i = 0; i < 505; ++i) {
		if(a[i] < 0) {
			return false;
		}
	}
	return true;
}

bool onlyCHANGE(string s, string t) 
{
	int a[505] = {};
	for (int i = 0; i < s.size(); ++i) {
		++a[s[i]];
	}
	for (int i = 0; i < t.size(); ++i) {
		--a[t[i]];
	}
	for (int i = 0; i < 505; ++i) {
		if (a[i] != 0) {
			return false;
		}
	}
	return true;
}

bool onlyDEL(string s, string t) {
	for (int i = 0; i < t.size(); ++i) {
		while (i < s.size() && s[i] != t[i]) {
			s.erase(i, 1);
		}
		if (i >= s.size()) {
			return false;
		}
	}
	return true;
}

int main()
{
	string s, t;
	while (cin >> s >> t) {
		if (bothmethods(s, t)) {
			if (onlyDEL(s, t)){
				cout << "automaton" << endl;
			}
			else if (onlyCHANGE(s, t)) {
				cout << "array" << endl;
			}
			else {
				cout << "both" << endl;
			}
		}
		else {
			cout << "need tree" << endl;
		}
	}
	return 0;
}