hdu 4639 Hehe 多校第四场

本文介绍了一个基于斐波那契数列的算法实现,该算法通过计算特定字符串模式出现的次数,并利用斐波那契数列进行计数。使用了C++语言进行编码,涉及字符串处理和斐波那契数列的计算。

是 he 的连续长度的 斐波那契数列   


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

const int maxn = 10100;
const int mod = 10007;
int f[maxn]={1,1,2};
char s[maxn];
int main()
{
    int T,cas=1;
    for(int i=3;i<maxn;i++) f[i]=(f[i-1]+f[i-2])%mod;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%s",s);
        int len=strlen(s);
        int ans=1;
        int t=0;
        for(int i=0;i<len;i++)
        {
            if(s[i]=='h'&&s[i+1]=='e')
            {
                t++;
                i++;
            }
            else
            {
                ans=ans*f[t]%mod;
                t=0;
            }

        }
        ans=ans*f[t]%mod;
        printf("Case %d: %d\n",cas++,ans);
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值