南阳oj-----Binary String Matching(string)
题目描述:
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
题目解析:
本题题意为在一个字符串ss中寻找子串s出现的次数
测试地址:测试点击此处
本题代码:
#include<iostream>
#include<string>
using namespace std;
void deal(string ss,string s)
{int sum=0,p;while(1){p=ss.find(s);if(p==-1)break;sum++;ss.replace(p,1,"q");//利用替换来防止重复查找}cout<<sum<<endl;
}
int main()
{int n;string s,ss;cin>>n;while(n--){cin>>s>>ss;deal(ss,s);}
return 0;
}
南阳oj-----Binary String Matching(string)相关推荐
- nyoj 题目5 Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alpha ...
- 南阳5--Binary String Matching(Kmp)
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alpha ...
- Binary String Matching
Binary String Matching 描述 Given two strings A and B, whose alphabet consist only '0' and '1'. Your t ...
- NYOJ Binary String Matching的stl解法 酒馆浪人的博客
Binary String Matching 时间限制: 3000 ms | 内存限制: 65535 KB 难度: 3 描述 Given two strings A and B, whose al ...
- Binary String Matching(C++)
题目描述: Given two strings A and B, whose alphabet consist only '0' and '1'. Your task is only to tell ...
- string matching(HDU-6629)
Problem Description String matching is a common type of problem in computer science. One string matc ...
- Expected binary or unicode string, got 3
Expected binary or unicode string, got 3 错误原因:对于y1,y2,由于直接把值赋给了dataframe类型的变量,而这一列本身是字符,赋予他是int时转成np ...
- String Matching 字符串匹配算法——干货从头放到尾
需要的先验知识:动态规划,有限状态机,搜索算法(就是含有state,action和policy)的模型,java.上面这些不需要知道很细,大概懂这些都是啥就可以读懂本文. 写这篇技术博客的动机是因为做 ...
- KY91 String Matching
KY91 String Matching 版本一:暴力解法 "版本一:暴力解法"import sys for line in sys.stdin:line = line.strip ...
- string++php,String 字符串
用户评论: [#1] cnbk201 at gmail dot com [2015-01-12 22:07:20] Small note to consider in heredoc multiple ...
最新文章
- StyleSheet文件中路径处理
- 深入理解JVM(2)——GC算法与内存分配策略
- navicat 官方使用手册,中文版,快捷键大全
- swift 雨燕 新手教程
- iPhone 12需求强劲 苹果计划将iPhone产量提升30%
- csharp:Compare two DataTables to rows in one but not the other
- 函数嵌套,关键字,闭包和装饰器
- 6.pragma pack
- 阿里云正式发布云原生人才培养合作计划
- asp木马伪装成图片或其它,上传漏洞终极解决方法
- WinXP升级IE6至IE8以及WIN7下IE8升级至IE11
- 华为IPD你学不会(转)
- cmd net use 命令
- C语言超市商品管理系统代码(精)
- c++ Simpson积分
- 手把手教你如何连接阿里云RDS云数据库
- js面试必备:原形链
- mysql中计算最大回撤_基金最大回撤算例(Java 1.8)
- mysql spring lobhandler_Spring让LOB数据操作变得简单易行
- excel股票今日走势计算机,怎样用excel 实时读取 股票日线数据
热门文章
- 人生苦短我用python(02)动态加载模块
- 生产环境-linux-tomcat宕掉-乌龙事件
- 在dll中用DirectSound8同时播放多个wav文件不能发声
- 微软4月13日发布Silverlight 4正式版
- rhel5编译安装2.6.29.2内核
- 面向对象闲话(一)——什么是对象
- 【Docker】总集篇
- pr生成html文件格式,pr支持哪些格式
- vue 中 v-if 和 v-for 混用时应该注意的事项
- ARM开发6.3.1 基础实训( 1 ) 单个数码 LED 的显示输出系统设计( 1)--LPC21XX