传送门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3203
题目大意给定一串字符串,需要计算出seven的个数。
#include<cstdio>
#include<cstring>
#include<string.h>
const int MAXN=10000+10;
char s[MAXN];
const char seven[]=" seven";
int main()
{
while(~scanf("%s",s))
{
long long dp[6]={1,0,0,0,0,0};
int len=strlen(s);
for(int i=0;i<len;i++)
{
if (s[i]>='A' && s[i]<='Z')
{
s[i]+='a'-'A';
}
for(int j=5;j>=1;j--)
{
if(seven[j]==s[i])
{
dp[j]+=dp[j-1];
}
}
}
printf("%lld\n",dp[5]);
}
}
本文介绍了一种使用C++编程语言解决计算给定字符串中seven出现次数的问题的方法。通过定义一个字符串数组并利用循环和条件判断,实现了高效地计数功能。

879

被折叠的 条评论
为什么被折叠?



