HDU 4639 Hehe(字符串处理,斐波纳契数列,找规律)

题目

//每次for循环的时候总是会忘记最后一段,真是白痴。。。。

//连续的he的个数  种数
//0                    1
//1                    1
//2                    2
//3                    3
//4                    5
//5                    8
//……                    ……
//斐波纳契数列

//不连续的就用相乘(组合数)好了

#include<iostream>
#include<algorithm>
#include<string>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
using namespace std;
#define ll __int64

//貌似刚刚数组开小了
int fi[6000];
void fiinit()
{
    fi[0]=1;
    fi[1]=1;
    for(int i=2;i<6000;i++)
    {
        fi[i]=(fi[i-1]+fi[i-2])%10007;
    }
}

int main(){
    fiinit();
    int n;
    scanf("%d",&n);
    for(int id=1;id<=n;id++)
    {
        char s[10100];
        scanf("%s",s);
        int len=strlen(s);
        int he=0;
        int ans=1;
        for(int i=0;i<len;)
        {
            if(s[i]=='h'&&s[i+1]=='e')
            {
                he++;
                i=i+2;
            }
            else 
            {
                if(he>1)
                    ans=(ans*fi[he])%10007;
                i++;
                he=0;
            }
        }
        //如果最后那个是he结尾,就要加上最后一段:
        if(he>1)
            ans=(ans*fi[he])%10007;

        printf("Case %d: %d
",id,ans);
    }
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/laiba2004/p/3915705.html