现在的位置: 首页 > 综合 > 正文

CodeForces 448B 小模拟

2019年04月11日 ⁄ 综合 ⁄ 共 740字 ⁄ 字号 评论关闭

最近写什么 WA什么烦死了,于是练练码力,水一水

顺便换个心情换个头像什么的 -  -

这道题难点就是找准什么时候用 "automaton" 什么时候 用 "array"(这不是废话吗)

#include <cstdio>
#include <cstring>
using namespace std;

char s[200],t[200];
int main()
{
    scanf("%s%s",s,t);
    int ls=strlen(s),lt=strlen(t);
    int hashs[26]={0},hasht[26]={0};///记录字母用数组
    if(lt>ls)                       ///t>s肯定是变不了的
    {
        puts("need tree");
        return 0;
    }
    int i=0,j=0,au=0,ar=0,f=0;
    while(i<ls)
    {
        if(s[i]==t[j])
        {
            f++;
            hasht[t[j++]-'a']++;
        }
        if(f==lt)                   ///不是中间断开肯定不要用array
            ar=-1;
        hashs[s[i++]-'a']++;
    }
    if(j!=lt)
        au=0;
    else
        au=1;
    //printf("j:%d\n",j);
    while(j<ls)
        hasht[t[j++]-'a']++;
    for(i=0;i<26;i++)
    {
        if(hashs[i]<hasht[i])
            break;
    }
    if(ar+1)                        ///如果ar不为-1时才判断是否用array
        if(i!=26) ar=0;
        else ar=1;
    else ar=0;

    if(ar&&ls!=lt)
        au=1;
    if(au&&ar)
        puts("both");
    else if(au)
        puts("automaton");
    else if(ar)
        puts("array");
    else
        puts("need tree");
    return 0;
}
【上篇】
【下篇】

抱歉!评论已关闭.