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

时间:2023-03-08 21:10:29
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[];
void fiinit()
{
fi[]=;
fi[]=;
for(int i=;i<;i++)
{
fi[i]=(fi[i-]+fi[i-])%;
}
} int main(){
fiinit();
int n;
scanf("%d",&n);
for(int id=;id<=n;id++)
{
char s[];
scanf("%s",s);
int len=strlen(s);
int he=;
int ans=;
for(int i=;i<len;)
{
if(s[i]=='h'&&s[i+]=='e')
{
he++;
i=i+;
}
else
{
if(he>)
ans=(ans*fi[he])%;
i++;
he=;
}
}
//如果最后那个是he结尾,就要加上最后一段:
if(he>)
ans=(ans*fi[he])%; printf("Case %d: %d\n",id,ans);
}
return ;
}