Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3
-
描述
-
Given two strings A and B, whose alphabet consist only ‘0’ and ‘1’. Your task is only to tell how many times does A appear as a substring of B? For example, the text string B is ‘1001110110’ while the pattern string A is ‘11’, you should output 3, because the pattern A appeared at the posit
-
输入
-
The first line consist only one integer N, indicates N cases follows. In each case, there are two lines, the first line gives the string A, length (A) <= 10, and the second line gives the string B, length (B) <= 1000. And it is guaranteed that B is always longer than A.
-
输出
-
For each case, output a single line consist a single integer, tells how many times do B appears as a substring of A.
-
样例输入
-
3
11
1001110110
101
110010010010001
1010
110100010101011
-
样例输出
-
3
0
3
-
//******BF算法***********/
#include
#include
#include
#include
#include
using namespace std; #define MAXSTRLEN 1000 int main() { char s[MAXSTRLEN+10]; char t[11]; int T; scanf("%d",&T); while(T--) { scanf("%s %s",t,s); int j=0,i=0; int len_s=strlen(s); int len_t=strlen(t); int count=0; while(i<=len_s) { if(s[i]==t[j]) { ++i; ++j; if(j==len_t) { count++; i=i-len_t+1; j=0; } } else { i=i-j+1; j=0; } } printf("%d\n",count); } return 0; }
<script type="text/java script">
-
<script type="text/java script">BAIDU_CLB_fillSlot("771048");
-
点击复制链接 与好友分享!
回本站首页
<script>
function copyToClipBoard(){
var clipBoardContent=document.title + '\r\n' + document.location;
clipBoardContent+='\r\n';
window.clipboardData.setData("Text",clipBoardContent);
alert("恭喜您!复制成功");
}
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
-
您对本文章有什么意见或着疑问吗?请到
论坛讨论您的关注和建议是我们前行的参考和动力??
-
上一篇:
hdu 1799 (循环多少次?)(排列组合公式)
-
下一篇:
Codeforces 476C Dreamoon and Sums (水
-
相关文章
-
<script type="text/java script">BAIDU_CLB_fillSlot("182716");
-
<script type="text/java script">BAIDU_CLB_fillSlot("517916");
-
图文推荐
<script>
(function(){
var appid = 'cyrBEfE7C',
conf = 'prod_830794cf494da8b808afb2994cfe0fee';
var doc = document,
s = doc.createElement('script'),
h = doc.getElementsByTagName('head')[0] || doc.head || doc.documentElement;
s.type = 'text/java script';
s.charset = 'utf-8';
s.src = 'http://assets.changyan.sohu.com/upload/changyan.js?conf='+ conf +'&appid=' + appid;
h.insertBefore(s,h.firstChild);
window.SCS_NO_IFRAME = true;
})()
-
<script type="text/java script">BAIDU_CLB_fillSlot("771057");
|