【ACM】Binary String Matching
Binary String Matching
- 描述
- 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
- 样例输出
-
- 3
- 0
- 3
- 3
思路:这个只是简单匹配,要是有时间限制的话,可以用KMP算法处理
- #include <iostream>
- #include <string>
- #include <algorithm>
- #include <cmath>
- #include <cstdio>
- using namespace std;
- int main(){
- int n;
- cin>>n;
- string a,b;
- while (n--)
- {
- cin>>a>>b;
- int count = ;
- for (int i = ; i < b.length(); i++)
- {
- int k = i;
- int j = ;
- while(k<b.length() && j<a.length()){
- if (j==a.length()- && b[k]==a[j])
- {
- count++;
- }
- if (b[k]==a[j])
- {
- k++;j++;
- }else{
- break;
- }
- }
- }
- cout<<count<<endl;
- }
- return ;
- }
【ACM】Binary String Matching的更多相关文章
- ACM Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
- 【LeetCode】字符串 string(共112题)
[3]Longest Substring Without Repeating Characters (2019年1月22日,复习) [5]Longest Palindromic Substring ( ...
- NYOJ之Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose a ...
- 【故障处理】ORA-28040: No matching authentication protocol
[故障处理]ORA-28040: No matching authentication protocol 1.1 BLOG文档结构图 1.2 前言部分 1.2.1 导读和注意事项 各位技术爱好者 ...
- Binary String Matching
问题 B: Binary String Matching 时间限制: 3 Sec 内存限制: 128 MB提交: 4 解决: 2[提交][状态][讨论版] 题目描述 Given two strin ...
- 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”
按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...
- Binary String Matching(kmp+str)
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
- NYOJ 5 Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
- 【CF662C】Binary Table(FWT)
[CF662C]Binary Table(FWT) 题面 洛谷 CF 翻译: 有一个\(n*m\)的表格(\(n<=20,m<=10^5\)), 每个表格里面有一个\(0/1\), 每次可 ...
随机推荐
- BZOJ1218:[HNOI2003]激光炸弹
我对状态空间的理解:https://www.cnblogs.com/AKMer/p/9622590.html 题目传送门:https://www.lydsy.com/JudgeOnline/probl ...
- CentOS6.5中的vsftpd安装配置
安装ftp 1.使用chkconfig 来查看是否装有vsftpd服务: 2.使用yum命令直接安装:yum -y install vsftpd 3.然后为它创建日志文件:touch /var/log ...
- Wireshark抓包常见问题解析
1. tcp out-of-order(tcp有问题) 解答: 1). 应该有很多原因.但是多半是网络拥塞,导致顺序包抵达时间不同,延时太长,或者包丢失,需要重新组合数据单元 因为他们可能是 ...
- 【转】 Pro Android学习笔记(二七):用户界面和控制(15):FrameLayout
FrameLayout FrameLayout通常只包含一个控件.如果我们在FrameLayout中设置多个控件,则第二个控件会堆叠在第一个控件上面,如此类推,一层一层地叠上去.下面的例子,我们在Fr ...
- 巧用函数实现js插入css样式
我用的是webstorm,当写css 样式时候,会没有提示,可以按Ctrl+Alt+Space.
- 用户收到"无法显示页面"的错误消息和"Connections_refused"条目记录在运行 Windows Server 2003,Exchange 2003 和 IIS 6.0 的服务器上的 Httperr.log 文件
症状 您会遇到下列症状在运行 Microsoft Windows Server 2003. Microsoft Exchange Server 2003年和 Microsoft Internet In ...
- oracle--分页过程demo1
oracle分页过程demo1: --ROWNUM用法 select o.*,rownum rn from (select * from emp) o where rownum<=10; sel ...
- shell入门-cut命令
命令:cut 选项:-d:-f 指定第几段由“:(分割符)”分割的段 -c 指定第几个字符 说明:选取命令,选取一段数据中我们想要的,一般是针对每行来分析选取的 [root@wangshaoj ...
- [凸包]Triangles
https://nanti.jisuanke.com/t/15429 题目大意:给出平面内$n$个整数坐标点,保证无三点共线.可以进行若干次连线,每次选择一个点对连接线段,但是任意两条线段都不得在给定 ...
- R: matrix & array 生成、操作矩阵、数组:
################################################### 问题:生成.操作矩阵 18.4.27 怎么生成矩阵 matrix.,,及其相关操作 ??? ...