EOJ Monthly 2017.12 (暨 ECNU 12 月内部选拔)G1. 唐纳德与子串 (Easy)

Time limit per test: 1.0 seconds

Memory limit: 256 megabytes

子串的定义是在一个字符串中连续出现的一段字符。这里,我们使用  s[lr]  来表示  s  字符串从  l  到  r (闭区间)的子串。在本题中,字符串下标从  0  开始。显然,对于长度为  n  的字符串共有  n(n+1)2  个子串。

对于一个给定的字符串  s ,唐纳德给出  q  次询问,第  i  次询问包括三个参数  li,ri,zi ,问在  s[liri]  的所有子串中共有多少个恰好为  zi

Input

输入具有如下形式:

sql1 r1 z1l2 r2 z2lq rq zq

第一行一个字符串  s

第二行一个整数  q

接下来每行:首先两个整数  li,ri  ( 0liri<|s| ),然后是一个非空字符串  zi 。整数和整数,整数和字符串间以单空格隔开。

字符串中只会出现  26  个小写英文字母。

数据规模约定:

  • 对于 Easy 档: 1|s|100,q|zi|100
  • 对于 Hard 档: 1|s|105,q|zi|105

Output

对于每次询问,输出一个整数,表示答案。

Examples

input
thisisagarbagecompetitionhahaha
5
0 30 a
1 5 is
25 30 hah
6 12 ag
7 12 ag
output
6
2
2
2
1

思路:

水题,模拟一遍即可。

代码:

#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<cstring>
#include<map>
using namespace std;
typedef long long ll;

int main()
{
    string str,z,temp;
    int q,i,l,r,len,num;
    cin>>str;
    cin>>q;
    while(q--)
    {
        scanf("%d%d",&l,&r);
        cin>>z;
        len=z.length();
        num=0;
        for(i=l;i<=r-len+1;i++)
        {
            temp=str.substr(i,len);
            if(temp==z)
                num++;
        }
        cout<<num<<endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值