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
      0
      3


Java实现

	private static int match(String a, String b) {
		int result = 0;
		int al = a.length();
		int bl = b.length();
		for(int i = 0; i < (bl - al + 1); i++){
			String sub = b.substring(i, i + al);
			if(sub.matches(a)){
				result++;
			}
		}
		return result;
	}
	
	private static void binaryStringMatch() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] a = new String[n];
		String[] b = new String[n];
		for(int i = 0; i < n; i++){
			a[i] = sc.next();
			b[i] = sc.next();
		}
		for(int i = 0; i < n; i++){
			System.out.println(match(a[i], b[i]));
		}
	}

 

ORB_SLAM3实战笔记:IMU与相机外参标定不准,到底有多大影响?(附D435i实测数据) 本文深入探讨了ORB_SLAM3中IMU与相机外参标定误差对SLAM精度的影响,特别是旋转偏差比平移误差更致命的原因。通过D435i实测数据,分析了不同外参设置下的轨迹误差,并提供了实用的标定验证方法和误差补偿技巧,帮助开发者提升视觉惯性SLAM系统的性能。 阅读详情

相关推荐

Imatest-Star模块(西门子星图)

星图分析指南:基于ISO12233标准的MTF测试方法,通过放射状射线和正弦灰度变化评估相机SFR性能。

weixin_64706696的博客 1574

NYOJ 题目5 Binary String Matching(string类使用)

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

Jogging_Clown 581

SAP ERP 物料主数据同步外围系统

w_input-beskz = i_marc_new-beskz."采购类型 " BESKZ--- ADD BY HX_FHJ 20210106。w_input-beskz = lw_marc-beskz."采购类型 " BESKZ--- ADD BY HX_FHJ 20210106。w_input-sobsl = i_marc_new-sobsl."特殊采购类型-虚拟物料标识。

ChampaignWolf的专栏 1747

acm-Binary String Matching

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 subs

zzyy17的专栏 663

深入解析线性反馈移位寄存器(LFSR)的工作原理与实现

本文深入解析了线性反馈移位寄存器(LFSR)的核心原理与实现方法。通过生动的比喻和详细的步骤拆解,阐述了LFSR如何通过反馈多项式和移位操作生成伪随机序列,并对比了斐波那契型与伽罗瓦型两种硬件结构。文章还涵盖了LFSR在数字电路测试、通信扰码及快速伪随机数生成等关键应用场景,同时指出了其在密码学中的局限性,并提供了Python和C语言的高效实现代码示例。

weixin_29007243的博客 545

39文章解读与程序——EI\CSCD\北大核心《基于两阶段鲁棒优化算法的微网多电源容量配置》已提供下载资源

电网论文源程序擅长文章解读,论文与完整源程序,等方面的知识,电网论文源程序关注python,机器学习,计算机视觉,深度学习,神经网络,数据挖掘领域.电网论文源程序擅长文章解读,论文与完整源程序,等方面的知识,电网论文源程序关注python,机器学习,计算机视觉,深度学习,神经网络,数据挖掘领域.《《《《《《《《更多资源还请持续关注本专栏》》》》》》》《《《《《《《《更多资源还请持续关注本专栏》》》》》》》论文与完整源程序_电网论文源程序的博客-优快云博客。电网论文源程序-优快云博客。

LIANG674027206的博客 1209
上一篇: 括号配对问题
下一篇: 三个数从小到大排序
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值