cf 625 b.War of the Corporations (字符串)
2016-03-02 22:50
459 查看
给出s1,s2两个字符串,要求修改字符串的字符,要求不能存在字串s2,问最少修改几个,其实找到相同的字符串后,修改最后一个字符,就可以直接跳到下一个字符...
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.
This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineapple did their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of the new artificial intelligence is
similar to the name of the phone, that Pineapple released 200 years ago. As all rights on its name belong to Pineapple, they stand on changing the name of Gogol's artificial intelligence.
Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of technology was already printed on all devices, the Gogol's director decided to replace some characters in AI name with "#".
As this operation is pretty expensive, you should find the minimum number of characters to replace with "#", such that the name of AI doesn't contain the name
of the phone as a substring.
Substring is a continuous subsequence of a string.
Input
The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100 000 characters. Second line contains the
name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English
letters.
Output
Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring.
Examples
input
output
input
output
input
output
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.
This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineapple did their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of the new artificial intelligence is
similar to the name of the phone, that Pineapple released 200 years ago. As all rights on its name belong to Pineapple, they stand on changing the name of Gogol's artificial intelligence.
Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of technology was already printed on all devices, the Gogol's director decided to replace some characters in AI name with "#".
As this operation is pretty expensive, you should find the minimum number of characters to replace with "#", such that the name of AI doesn't contain the name
of the phone as a substring.
Substring is a continuous subsequence of a string.
Input
The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100 000 characters. Second line contains the
name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English
letters.
Output
Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring.
Examples
input
intellect tell
output
1
input
google apple
output
0
input
sirisiri sir
output
2
#include<bits/stdc++.h> using namespace std; char a[111111],b[33]; int main() { int n,m,i,j,ans; ans=0; scanf("%s%s",a,b); n=strlen(a); m=strlen(b); for(i=0;i<n;i++) { for(j=0;j<m&&i+m<=n;j++) { if(a[i+j]!=b[j]) break; } if(j==m) { ans++; i=i+m-1; } } printf("%d\n",ans); return 0; }
相关文章推荐
- Android学习之GridLayout与GridView
- [LeetCodeOJ] Reverse Integer
- 前端框架Bootstrap的Modal使用Ajax数据源,如何避免数据被缓存
- intellij idea 12/15 报错“非法字符: \65279”
- jquery 事件綁定
- SQL Server语法学习笔记
- Hibernate学习篇01——Hibernate基础
- Mybatis批量增加,删除,更新Oracle
- 01背包
- Educational Codeforces Round 9 E. Thief in a Shop dp fft
- bzoj 1090: [SCOI2003]字符串折叠
- Netty线程模型
- 浅谈WPF DatePicker默认显示 当前时间
- Maven集成到工具以及解决内存溢出
- 打log分析安卓密钥
- slf4j源码解析
- linux挂载空磁盘步骤
- Android Listview滑动时不加载数据,停下来时加载数据,让App更优
- HTML系列(四):编辑图像
- Spring 中使用Properties文件