binary string match
来源:互联网 发布:软件质量分析师 编辑:程序博客网 时间:2024/04/30 04:55
我是逐个比较,每次取出对应的位置来比较。。当然也可以用strcmp,只是字符数组取出来还要变成字符串加\0比较烦。。
这个算法一定要注意flag的重置位置。。第一次就搞错了
Mark April 7,Monday 2014 USC
有问题大家留言~?
重新换了一下c++中得string find写了一下。。简洁了很多。
#include<stdio.h>#include<iostream>#include<string.h>using namespace std;int main(){char strA[11];char strB[1001];bool flag=true;int line,lenA,lenB,match=0;cin>>line;while(line--){ match=0;cin>>strA;cin>>strB;lenA=strlen(strA);lenB=strlen(strB); for(int i=0;i<(lenB-lenA+1);i++) { flag=true; for(int j=0;j<lenA;j++) { if(strA[j]!=strB[j+i]) { flag=false; break; } } if(flag==true) match++; } cout<<match<<endl;}}
#include<stdio.h>#include<iostream>#include<string.h>#include<string>using namespace std;using namespace std;int main(){string s1,s2;int n;cin>>n;while(n--){cin>>s1>>s2;int m=-1;int num=-1; do { num++; m=s2.find(s1,m+1); }while(m!=string::npos);cout<<num<<endl;}}
0 0
- binary string match
- BM string match algorithm
- string search and match
- String.prototype.match()
- systemverilog string match
- 686. Repeated String Match
- 686. Repeated String Match
- Leetcode | Repeated String Match
- JavaScript String 对象 match() 方法
- Data structure-String-Pattern match
- JavaScript 中的 String.match() 方法
- JavaScript string对象match()方法
- leetcode 686 Repeated String Match
- leetcode 686. Repeated String Match
- leetcode 686. Repeated String Match
- [LC]686. Repeated String Match
- leetcode 686. Repeated String Match
- 【LeetCode】686. Repeated String Match
- 网络121第6周实验——GUI及多媒体编程
- MapReduce简介及执行过程详解
- uva 1548 - The Game of Master-Mind(dfs+剪枝)
- Ztree 3.5 实践笔记
- python怎么判断IP地址的合法性
- binary string match
- 积分墙广告的七个真相(触控软文)
- php正则表达式匹配img中任意属性
- 玩家离开手游的5大原因 前60秒最重要
- php 正则表达式匹配中文
- 第三章实验作业2
- NoSql学习之路一redis做消息队列
- 【索引】Designing Efficient Algorithms:Examples:Intermediate
- 第五届蓝桥杯C/C++本科A组初赛波动数列解题报告