Binary String Matching
来源:互联网 发布:商城 域名取名 编辑:程序博客网 时间:2024/05/14 12:14
<dt style="font-family: Tahoma, Arial, sans-serif, simsun; line-height: 26px; margin: 1em 0px 0.2em; padding: 0px; color: rgb(113, 32, 21); font-size: 16px; font-weight: bold;">描述</dt><dd style="color: rgb(70, 70, 70); font-family: Tahoma, Arial, sans-serif, simsun; font-size: 14px; line-height: 26px; margin: 0px; padding: 0px;">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<div class="clr" style="clear: both;"></div><dl class="others" style="margin: 0px; padding: 0px;"><dt style="margin: 1em 0px 0.2em; padding: 0px; color: rgb(113, 32, 21); font-size: 16px; font-weight: bold;">输入</dt><dd style="margin: 0px; padding: 0px;">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.</dd><dt style="margin: 1em 0px 0.2em; padding: 0px; color: rgb(113, 32, 21); font-size: 16px; font-weight: bold;">输出</dt><dd style="margin: 0px; padding: 0px;">For each case, output a single line consist a single integer, tells how many times do B appears as a substring of A.</dd><dt style="margin: 1em 0px 0.2em; padding: 0px; color: rgb(113, 32, 21); font-size: 16px; font-weight: bold;">样例输入</dt><dd style="margin: 0px; padding: 0px;"><pre id="sample_input" style="white-space: pre-wrap; word-wrap: break-word; margin-top: 0px; margin-bottom: 0px; padding: 5px 10px; font-family: Consolas, 'Courier New', 'DejaVu Sans Mono', 'Droid Sans Mono', monospace; border: 1px solid rgb(204, 204, 204); min-height: 20px; line-height: 1.5em; background-color: rgb(239, 239, 239);">31110011101101011100100100100011010110100010101011
303
#include<iostream>#include<string>using namespace std;int main(){string s1,s2;int n;cin>>n;while(n--){cin>>s1>>s2;unsigned int m=s2.find(s1,0);int num=0;while(m!=string::npos){num++;m=s2.find(s1,m+1);}cout<<num<<endl;}}
0 0
- Binary String Matching
- Binary String Matching
- Binary String Matching
- Binary String Matching
- 【Binary String Matching 5】
- acm-Binary String Matching
- Binary String Matching
- 5 Binary String Matching
- 南阳--Binary String Matching
- Binary String Matching
- Binary String Matching
- Binary String Matching
- Binary String Matching
- Binary String Matching
- Binary String Matching
- Binary String Matching
- Binary String Matching
- Binary String Matching
- HDU - 4614 Vases and Flowers(线段树 区间修改 二分)
- c语言获取当前可执行文件的执行路径个文件名
- Android View 生命周期
- C++的一些模块学习!
- 5.3.8 绘图模式
- Binary String Matching
- HP-UX vPars and Integrity 为vm guest添加、删除磁盘
- 电源管理方案APM和ACPI比较
- UILabel intrinsicContentSize adjustsFontSizeToFitWidth 用法
- Selenium2的相关知识点
- 工作中常见错误集合及解决方法
- .NET 垃圾回收浅解
- self 的循环引用
- 中兴面试程序-年龄问题