CodeForces 625B War of the Corporations
2016-02-14 00:28
363 查看
暴力匹配+一点判断
#include <stdio.h> #include <algorithm> #include <string.h> #include <queue> #include <stack> #include <map> #include <vector> using namespace std; const int maxn=100000+50; char s[maxn]; char t[35]; struct Seg { int l,r; Seg(int a,int b){l=a;r=b;} }; vector<Seg>v; int L,R; bool CMP(int pos) { bool flag=1; for(int i=0;t[i];i++) { if(t[i]!=s[i+pos]) {flag=0;break;} } return flag; } int main() { scanf("%s",s); scanf("%s",t); v.clear(); int lens=strlen(s); int lent=strlen(t); for(int i=0;i<lens;i++) { if(CMP(i)) { Seg seg(i,i+lent-1); v.push_back(seg); } } int ans; if(v.size()==0) ans=0; else { ans=1; L=v[0].l,R=v[0].r; for(int i=1;i<v.size();i++) { if(v[i].l<=R) L=v[i].l; else { ans++; L=v[i].l; R=v[i].r; } } } printf("%d\n",ans); return 0; }
相关文章推荐
- CodeForces 625A Guest From the Past
- php unicode
- CodeForces 625D Finals in arithmetic
- 杭电1017
- Java线程学习经典例子-读写者演示
- 用Qt实现一个桌面弹幕程序(二)--实现一个弹幕①
- MOOC Machine learning 作业交流帖1
- 了解HTML CSS格式化排版 文字排版
- 禁止UITextField 使用粘贴复制功能
- 经典同步模型-生产者消费者java代码实现
- GDAL获取投影坐标系注意问题
- 1037. Magic Coupon (25)
- hdu2196 Computer(树型dp,两次bfs)
- UIStackView相关
- JSP中的EL隐式对象
- LeetCode 62. Unique Paths
- 寻路算法模拟器
- 手工matlab下K-means聚类算法实现而不是调用库函数
- 《Android源码设计模式》读书笔记 (5) 第5章 工厂模式
- JVM 栈 堆 内存泄露 调优