Codeforces 625B War of the Corporations (字符串匹配题目)
2016-03-08 01:07
337 查看
B. War of the Corporations
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard 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.
Sample test(s)
input
intellect
tell
output
1
input
google
apple
output
0
input
sirisiri
sir
output
2
Note
In the first sample AI’s name may be replaced with “int#llect”.
In the second sample Gogol can just keep things as they are.
In the third sample one of the new possible names of AI may be “s#ris#ri”.
本题是一个找子串个数的水题,,,我在这里就不再进行吐槽了,,。。直接附上AC代码。。大家看一下吧。。。
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard 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.
Sample test(s)
input
intellect
tell
output
1
input
apple
output
0
input
sirisiri
sir
output
2
Note
In the first sample AI’s name may be replaced with “int#llect”.
In the second sample Gogol can just keep things as they are.
In the third sample one of the new possible names of AI may be “s#ris#ri”.
本题是一个找子串个数的水题,,,我在这里就不再进行吐槽了,,。。直接附上AC代码。。大家看一下吧。。。
#include<cstdio> #include<cstring> #include<cmath> #include<iostream> using namespace std; char a[100050]; char b[100]; int judge(int la,int lb) { int s=0; for(int i=0;i<lb;i++) { if(a[la]==b[i]) { s++; la++; } else { break; } } if(s==lb) { return 1; } else return 0; } int main() { while(~scanf("%s%s",a,b)) { int la=strlen(a); int lb=strlen(b); int sum=0; for(int i=0;i<la;i++) { if(a[i]==b[0]) { int result=judge(i,lb); if(result==1) { sum++; i=i+lb-1; } } } printf("%d\n",sum); } return 0; }
相关文章推荐
- php调试——输出变量值
- hash+链表
- Spring高级事务管理难点剖析
- 报Unable to find debug key in keystore!错的原因
- Kalman Filter的推导与应用(二)
- Http 协议基础笔记之入门篇
- ios 常见错误记录
- WebView加载进度Progress的显示
- 北漂行记--妇女节阶段总结
- ios中的多线程
- 连接AdapterView视图和数据源的桥梁:Adapter适配器(3)
- 小课堂开始录播了
- Android应用开发基础之九:内容提供者(ContentProvider)
- Android项目实战--【谁是歌手-布局篇】
- Mac 安装和配置gradle
- android_activity之startActivityForResult的使用
- android 一条线
- CocoaPods使用
- 【C语言】实现字符串右移位函数
- node.js在linux下的安装