Binary String Matching
来源:互联网 发布:dos命令和linux命令 编辑:程序博客网 时间:2024/05/22 02:09
描述
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
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
import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();List<Object> list = new ArrayList<Object>();for (int i = 0; i < n; i++) {Map<String, String> map = new HashMap<String, String>();String str1 = sc.next();String str2 = sc.next();map.put("str1", str1);map.put("str2", str2);list.add(map);}print(list);}private static void print(List<Object> list) {for (int i = 0; i < list.size(); i++) {@SuppressWarnings("unchecked")Map<String, String> map = ((Map<String, String>) list.get(i));String str1 = (String) map.get("str1");String str2 = (String) map.get("str2");match(str1, str2);}}static void match(String str1, String str2) {int i, count = 0;i = str2.indexOf(str1);// strB在strA中首次出现的位置while (i >= 0) {count++;i = str2.indexOf(str1, i + 1);}System.out.println(count);}}
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
- 单元测试JUnit
- 对象序列化输出 Serializable
- MySQL 面试中的问题汇总
- Linux自动备份压缩MySQL数据库的实用方法
- 证明:(0,0)到(x,y)连线上横纵坐标都是正整数的点有gcd(x,y)个
- Binary String Matching
- redis学习笔记(9)---对象robject
- 一种排序
- jQuery-遍历
- 设计模式---单例模式
- 语法篇6之string
- Mozilla Rust最近发布的MIR的一个评论
- 理解MVC,MVP和MVVM设计模式
- poj3261最长重复k次子串