codeforces 448 B. Suffix Structures

来源:互联网 发布:怎样进入上层社会 知乎 编辑:程序博客网 时间:2024/06/06 03:52

题目链接:http://codeforces.com/contest/448/problem/B
题目大意:已知字符串a,b,要把a转换成b。如需删除输出automaton,如需交换输出array,都需要输出both,不可能成功输出need tree。
提示:用两个数组记一下26个字母的个数,在比较字母个数的大小,也就是先找need tree的时候

#include <iostream>#include <cstring>#include <cstdio>using namespace std;char a[105];char b[105];int main(){    int suma[26]={0};    int sumb[26]={0};    cin>>a>>b;    int lena=strlen(a);    int lenb=strlen(b);    for(int i=0; i<lena; i++)        suma[a[i]-'a']++;    for(int i=0; i<lenb; i++)        sumb[b[i]-'a']++;    int arr=0;    int aut=0;    int f=0;    for(int i=0; i<26; i++)    {        if(suma[i] < sumb[i])        {            puts("need tree");            f=1;            break;        }        if(suma[i]>sumb[i])            aut=1;    }    if(f)        return 0;    int pos=0;    for(int i=0; i<lenb; i++)    {        int flag=0;        for(int j=pos; j<lena; j++)        {            if(a[j] == b[i])            {                pos=j+1;                flag=1;                break;            }        }        if(flag == 0)        {            arr=1;            break;        }    }    if(arr == 1 && aut == 1)        puts("both");    else if(arr == 1)        puts("array");    else        puts("automaton");    return 0;}
0 0
原创粉丝点击