ZOJ 3171 The Hidden 7's DP

传送门: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]);
	}
}


你可能感兴趣的:(ZOJ 3171 The Hidden 7's DP)