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

来源:互联网 发布:晨光麦事件 知乎 编辑:程序博客网 时间:2024/05/25 08:13
#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;}

0 0
原创粉丝点击