广州大学第九届ACM B--再来一道


B - 再来一道

Time Limit:  2000/1000 MS (Java/Others)       Memory Limit:  128000/64000 KB (Java/Others) 
Problem Description

XiaoMing is so lazy that he was sleeping in his English lessons, so his English teacher punished him to calculate how many times 

that "sleep" and "sleepy" appear altogether in a given English string, and the string’s length is not greater than 1,000,000.

Input

The first line of the input contains an integer T(1<=T<=11) which means the number of test cases.

Each case contains a English string(which maybe contains lowercase, ‘,’, ’.’, and ’?’, but not ‘ (space)‘) in a single line.

Output

For each case, you need to print the answer in a single line.

Sample Input
5
sleep.....y
sl.eep
xxsleepsleepyyyboring
sleeppppppppppppppppppp
fifjfjo,hhhfijdfij.efejo?fdffdf
Sample Output
1
0
3
1
0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* this code is made by 1406100108
* Problem: 1353
* Verdict: Accepted
* Submission Date: 2015-04-14 14:29:13
* Time: 12 MS
* Memory: 2380 KB
*/
#include<iostream>
#include<cstring>
using namespace std;
 
int main()
{
     char text[1000001];
     unsigned  int i,lg,T ,count;          //lg为字符串长
     cin>>T;
     while (T--)
     {
         count = 0;
         cin>>text;
         lg= strlen (text);
         for (i=0;i<lg;++i)
         {
             if (text[i]== 's' )
                 if (text[i+1]== 'l' )
                     if (text[i+2]== 'e' )
                         if (text[i+3]== 'e' )
                             if (text[i+4]== 'p' )
                             {
                                 ++count;
                                 if (text[i+5]== 'y' )
                                     ++count;
                             }
         }
         cout<<count<<endl;
     }
     return 0;
}

这道题比较简单,主要就是寻找sleep和sleepy,注意在寻找到sleep时再后面可以再判断一下有没有y,有则累加。用这种方法破解有点暴力,缺乏简洁,这里还可用<string>

库里的字符串寻找函数,这样的话定义时应该定义成string   str。用直接寻找串内的子串。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值