Codeforces Round #256 (Div. 2) B Suffix Structures
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
automaton
tomat
automaton
array
arary
array
both
hot
both
need
tree
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的更多相关文章
- Codeforces Round #256 (Div. 2) B. Suffix Structures(模拟)
题目链接:http://codeforces.com/contest/448/problem/B --------------------------------------------------- ...
- Codeforces Round #256 (Div. 2/B)/Codeforces448B_Suffix Structures(字符串处理)
解题报告 四种情况相应以下四组数据. 给两字符串,推断第一个字符串是怎么变到第二个字符串. automaton 去掉随意字符后成功转换 array 改变随意两字符后成功转换 再者是两个都有和两个都没有 ...
- Codeforces Round #256 (Div. 2) 题解
Problem A: A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #256 (Div. 2)
A - Rewards 水题,把a累加,然后向上取整(double)a/5,把b累加,然后向上取整(double)b/10,然后判断a+b是不是大于n即可 #include <iostream& ...
- 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 ...
- Codeforces Round #256 (Div. 2) B (448B) Suffix Structures
题意就是将第一个字符串转化为第二个字符串,支持两个操作.一个是删除,一个是更换字符位置. 简单的字符串操作!. AC代码例如以下: #include<iostream> #include& ...
- Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)
转载请注明出处:viewmode=contents" target="_blank">http://blog.csdn.net/u012860063?viewmod ...
- 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 ...
- 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 ...
随机推荐
- Ubuntu 16.04 samba相关配置
samba是 SMB/CIFS网络协议的重新实现,它作为NFS的补充使得在Linux和Windows系统之间进行文件共享.打印更容易实现. 相关介绍: SAMBA套件: (1)samba:这个套件主要 ...
- JFrame
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class KeyDemo extends JFram ...
- Gs_Class._BaseQueryWeb查询页面基类(aspx.net)
using System;using System.Data;using System.Configuration;using System.Collections;using System.Web; ...
- 安装配置Postgresql
//关闭selinuxgetenforcesetenfroce 0vi /etc/selinux/configSELINUX=disabledSELINUXTYPE=targeted//关闭防火墙#c ...
- C# 语言规范_版本5.0 (第6章 转换)
1. 转换 转换(conversion) 使表达式可以被视为一种特定类型.转换可导致将给定类型的表达式视为具有不同的类型,或其可导致没有类型的表达式获得一种类型.转换可以是隐式的 (implicit) ...
- git在webstorm中的使用
打开webstorm新建项目,这里新建的项目名称我起为lianxi 打开设置选项里的插件栏 搜索gitignore,并安装,我这里已安装,所以显示X,没有安装的会显示一个绿色的下载箭头.安装完后需要重 ...
- Cocoapod安装使用和常见问题(转载)
1.cocoapod的按照,cocoapod是运行在ruby环境下的,在ruby环境的 ,像cocoapod这样的开源项目时放在放在rubygems服务器上面的,但国内访问https://ruby ...
- php笔记(八)PHP类与对象之抽象类
<?php //通过abstract关键字定义一个抽象类 abstract class ACanEat{ //通过abstract关键字定一个不用具体实现的抽象方法eat() abstract ...
- Jsp中out.println()与System.out.println()的区别
第一次上Web实验课时咱写了一个jsp程序: <% System.out.println("Hello The World"); %> 然后放在浏览器下运行,结果是这样 ...
- python修炼4
---恢复内容开始--- 集合 建立 set() ={},集合没有顺序,由不可改变的数字 ,字符串,元组构成 #交集print(a&b) #a.intersection(b) #并集prin ...