Oulipo
2015-07-07 18:26
411 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1686
#include<iostream>
#include<string>
using namespace std;
int next1[100002];
int mount;
void getnext(string s)
{
int i=0,j=-1;
next1[0]=-1;
while(i<s.size())
{
if(j==-1 || s[i]==s[j])
{
i++;
j++;
next1[i]=j;
}
else
j=next1[j];
}
}
void match(string w,string t)
{
int i=0,j=0;
while(i<t.size())
{
if(j==-1 || t[i]==w[j])
i++,j++;
else
j=next1[j];
if(j==w.size())
{
mount++;
j=next1[j];
}
}
}
int main()
{
// freopen("C:\\Users\\John\\Desktop\\hi.txt","r",stdin);
int t1;
string w,t;
cin>>t1;
while(t1--)
{
mount=0;
cin>>w>>t;
if(t.size()<w.size())
{
cout<<"0"<<endl;
continue;
}
getnext(w);
match(w,t);
cout<<mount<<endl;
}
return 0;
}
http://acm.hdu.edu.cn/showproblem.php?pid=1686
#include<iostream>
#include<string>
using namespace std;
int next1[100002];
int mount;
void getnext(string s)
{
int i=0,j=-1;
next1[0]=-1;
while(i<s.size())
{
if(j==-1 || s[i]==s[j])
{
i++;
j++;
next1[i]=j;
}
else
j=next1[j];
}
}
void match(string w,string t)
{
int i=0,j=0;
while(i<t.size())
{
if(j==-1 || t[i]==w[j])
i++,j++;
else
j=next1[j];
if(j==w.size())
{
mount++;
j=next1[j];
}
}
}
int main()
{
// freopen("C:\\Users\\John\\Desktop\\hi.txt","r",stdin);
int t1;
string w,t;
cin>>t1;
while(t1--)
{
mount=0;
cin>>w>>t;
if(t.size()<w.size())
{
cout<<"0"<<endl;
continue;
}
getnext(w);
match(w,t);
cout<<mount<<endl;
}
return 0;
}
相关文章推荐
- 自定义tabBar控制器
- 83.在数组中删除给出的数
- win32写入粘贴板
- Android之mk文件学习笔记
- Openshift SDN node vxlan 流程
- java编程思想----构造器
- Debian上安装rz/sz包
- 加快easyui的datagrid的数据渲染
- [leedcode 21] Merge Two Sorted Lists
- Android-异步任务介绍及面试题
- 关于Class.getResource和ClassLoader.getResource的路径问题
- 常见操作系统
- Oracle 中 decode 函数用法
- CoreText 实现图文混排
- 【翻译】使用Sencha Ext JS 6打造通用应用程序
- ffmpeg 编码h264 profile如何设置为baseline的问题
- H264 各种profile
- 【翻译】使用Sencha Ext JS 6打造通用应用程序
- 【翻译】使用Sencha Ext JS 6打造通用应用程序
- 万网虚拟空间二级域名绑定子目录