CodeForces 448B 小模拟

最近写什么 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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值