UESTC 1595 寻找算法

来源:互联网 发布:300339润和软件 编辑:程序博客网 时间:2024/05/22 10:26

Description

pfctgeorge很喜欢algorithm这个词,他总在到处找这个词。
现在他拿到一些英文写的文章,他想删掉一些字符,使得最后剩下的字符接起来以后是一个接一个的"algorithm"。
请问pfctgeorge最后能得到最多多少个"algorithm"?

Input

输入的第一行是一个整数T(T<=50),表示有T段文章。
接下来T行,每行是一个长度不大于1000字符串,由小写字母或者空格、逗号、句号组成,表示一段文章。

Output

对于每一段文章,输出一行,只包含一个整数,表示最后能得到"algorithm"最多的个数。

Sample Input

3
i love algorithm, and i have an algorithmic problem. can you help me?
reverse it, and get mhtirogla.
there is a large orange in the microwave oven.

Sample Output

2
0
1

题解:从第一位开始往后面找algorithm看是否存在。

#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <cmath>#include <algorithm>using namespace std;char f[10]={"algorithm"};char s[1010];int main(){int T,i;scanf("%d",&T);getchar();while (T--){char s[1010];gets(s);int l=strlen(s);int j=0,t=0;for (i=0;i<l;i++){if (f[j]==s[i])j++;if (j>8) {j=0;t++;}}printf("%d\n",t);} return 0;}




原创粉丝点击