Description

You are given two strings s and t, both consisting only of lowercase Latin letters.The substring s[l..r] is the string which is obtained by taking characters sl,sl+1,…,sr without changing the order.
Each of the occurrences of string a in a string b is a position i (1≤i≤|b|−|a|+1) such that b[i..i+|a|−1]=a (|a| is the length of string a).
You are asked q queries: for the i-th query you are required to calculate the number of occurrences of string t in a substring s[li..ri].

Input
The first line contains three integer numbers n, m and q (1≤n,m≤103, 1≤q≤105) — the length of string s, the length of string t and the number of queries, respectively.
The second line is a string s (|s|=n), consisting only of lowercase Latin letters.

The third line is a string t (|t|=m), consisting only of lowercase Latin letters.

Each of the next q lines contains two integer numbers li and ri (1≤li≤ri≤n) — the arguments for the i-th query.

Output

Print q lines — the i-th line should contain the answer to the i-th query, that is the number of occurrences of string t in a substring s[li..ri].

Sample Input
Input

10 3 4
codeforces
for
1 3
3 10
5 6
5 7

Output

0
1
0
1

Input

15 2 3
abacabadabacaba
ba
1 15
3 4
2 14

Output

4
0
3

Input

3 5 2
aaa
baaab
1 3
1 1

Output

0
0

Hint

In the first example the queries are substrings: "cod", "deforces", "fo" and "for", respectively.

题目意思:给出一条母串,给出一条子串,查询母串的某一个区间,问该区间有多少条子串。

解题思路:我是用string中的find来做的,find可以有两个参数,一个是子串,一个是在母串中的位置,也就是开始查询的位置,先利用find找到所有子串的起始位置,相当于打了一张表,之后查询区间,就是访问该区间中合法的子串起始位置的数量,注意子串的长度+起始位置不能越界!

 #include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n,m,q,i,j,l,r,len;
int counts;
int vis[];
string s1,s2;
cin>>n>>m>>q;
cin>>s1>>s2;
len=s2.size();
memset(vis,,sizeof(vis));
string::size_type pos=;
while((pos=s1.find(s2,pos))!=string::npos)
{
vis[pos+]=pos+;
pos++;
}///打表标记母串中出现子串的位置
for(i=;i<=q;i++)
{
counts=;
scanf("%d%d",&l,&r);
for(j=l;j<=r;j++)
{
if(vis[j]!=&&vis[j]+len-<=r)///查询区间内出现子串并且不会越界
{
counts++;
}
}
printf("%d\n",counts);
}
return ;
}

Segment Occurrences(string find函数)的更多相关文章

  1. Educational Codeforces Round 48 (Rated for Div. 2) B 1016B Segment Occurrences (前缀和)

    B. Segment Occurrences time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  2. java String.split()函数的用法分析

    java String.split()函数的用法分析 栏目:Java基础 作者:admin 日期:2015-04-06 评论:0 点击: 3,195 次 在java.lang包中有String.spl ...

  3. string.capwords()函数

    string.capwords()函数 string.capwords()函数,有需要的朋友可以参考下. 代码 : import syssys.path.append("C:/Python2 ...

  4. public static void main(String[] args){}函数诠释

    public static void main(String[] args){}函数诠释 主函数的一般写法如下: public static void main(String[] args){-} 下 ...

  5. Js对象转String的函数 和 JSON转String

    js对象转string的函数 function obj2str(o){ var r = []; if(typeof o =="string") return "" ...

  6. String.Split()函数

    我们在上次学习到了 String.Join函数(http://blog.csdn.net/zhvsby/archive/2008/11/28/3404704.aspx),当中用到了String.SPl ...

  7. java中string.trim()函数的使用

    java中string.trim()函数的的作用是去掉字符串开头和结尾的空格,防止不必要的空格导致的错误. public static void main(String arg[]){ String ...

  8. String.Split()函数 多种使用实例

    我们在上次学习到了 String.Join函数(http://blog.csdn.net/zhvsby/archive/2008/11/28/3404704.aspx),其中用到了String.SPl ...

  9. string的函数的学习

    1.string类型的构造函数和对象的定义 string s3 : 把string s2 拷贝的 s3 string s4 : 把数组首地址或者字符串首地址strArr 从0开始截取到第n个字母 st ...

  10. Torch-RNN运行过程中的坑 [2](Lua的string sub函数,读取中文失败,乱码?)

    0.踩坑背景 仍然是torch-rnn/LanguageModel.lua文件中的一些问题,仍然是这个狗血的LM:encode_string函数: function LM:encode_string( ...

随机推荐

  1. 辽宁移动宽带体验及魔百盒M101s-2刷机

    一.背景 坐标:辽宁 某城,移动宽带100M. 设备:移动赠送,华为光猫一只,魔百盒M101s-2电视盒子 一只,据安装人员说这个魔百盒是移动自己开发设计的. 二.上网体验 上网:浏览一般网站没问题. ...

  2. Unity3d Platformer Pro 2D游戏开发框架使用教程

    前言 Platformer Pro框架是Unity3d AssetStore上一个非常强大和受欢迎的2d游戏开发框架,这个教程的大部分翻译于官方文档,一部分是工作总结,还有一部分是视频教程文档化.这个 ...

  3. 17秋 软件工程 团队第五次作业 Alpha 用户反馈

    用户反馈 Bug 测试对不同机型进行了测试,包括: 小米NOTE, MIUI 8.5 稳定版 [已修复]点登录按钮之后自动退出: [已修复]登录界面的背景图片没有显示. 小米4 [已修复]闪退,无法打 ...

  4. [java大数据面试] 2018年4月百度面试经过+三面算法题:给定一个数组,求和为定值的所有组合.

    给定一个数组,求和为定值的所有组合, 这道算法题在leetcode应该算是中等偏下难度, 对三到五年工作经验主要做业务开发的同学来说, 一般较难的也就是这种程度了. 简述经过: 不算hr面,总计四面, ...

  5. Nginx SSL TLS部署最佳实践

    本文介绍nginx在提供HTTPS时使用的一些其他配置选项. 虽然这些功能有助于优化nginx的SSL和TLS,但这不是一个完整对加固nginx的介绍. 确保您的服务器安全的最佳方法是不仅需要正确的配 ...

  6. 2018年值得关注的10大JavaScript动画库

    2018年值得关注的10大JavaScript动画库 旭日云中竹 前端早读课 1周前 前言 平时大家开发动画是采用什么方式呢?虽然18年过半,可这十个动画库是真的没听过几个,有点尴尬.今日早读文章由@ ...

  7. GUI练习3

    将阿里山的积分卡拉斯的发生的咖啡机啊圣考虑到发送到敬爱费卢卡斯加

  8. File类_常见的方法(获取目录中指定规则的内容)

    首先定义过滤器 import java.io.File; import java.io.FilenameFilter; public class FileByJava implements Filen ...

  9. 2个Excel表格核对技巧

    技巧1.利用Spreadsheet Camprare一秒钟识别差异数据 如下图所示,我们如何快速比对我们自己做的表格和上司修改后的表格的差异呢?这里首先来介绍一个非常棒的工具:Spreadsheet ...

  10. web测试工具列表

    ab.webbench,siege,loadrunner(专业的测试软件可形成图表.) 推荐使用ab测试. tcp并发测试: c1000k