Codeforces Round #342 (Div. 2)(B)贪心


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".



题意:给你2个字符串s1,s2,问你至少要修改几次才可以使s1串不包含s2串



题解:莫名其妙就AC了,原因是我就是想到一个样例


qwqwqwqwqw

qwq


于是我每次查找到子串s2,我修改最后的那个字符可以尽可能的减少修改次数,否则就会出现链锁反应,大概这一题就是考察这个样例吧


#include 
#include 
#include  
#include  
#include  
#include 
#include  
#include  
#include 
#include  
#include  
#include 
#include 
#define LL  long long 
using namespace std;
#define N 100005
#define inf 0x3f3f3f3f3f3f3f3f
char s1[N],s2[N];
int main()
{
#ifdef CDZSC
	freopen("i.txt","r",stdin);
#endif
	while(~scanf("%s%s",s1,s2))
	{
		int lg=strlen(s2),ans=0;
		for(int i=0;s1[i];i++)
		{
			int len=0;
			for(int j=0;s2[j];j++)
			{
				if(s1[i+j]==s2[j])
				{
					len++;
				}
			}
			if(len==lg)
			{
				ans++;
				s1[i+len-1]='#';
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}









你可能感兴趣的:(-----基础算法-----,构造)