codeforces #342 div 2 B. War of the Corporations
http://codeforces.com/contest/625/problem/B 题意:给出两个字符串,问要替换掉多少个字符才能使得前者中不包含后者。 思路:直接搞...找到一个把收尾替换成‘#’,然后下次从该位置继续开始找,直到找不到。
/* ***********************************************
Author :111qqz
Created Time :2016年02月07日 星期日 17时31分33秒
File Name :code/cf/#342/B.cpp
************************************************ */
1#include <cstdio>
2#include <cstring>
3#include <iostream>
4#include <algorithm>
5#include <vector>
6#include <queue>
7#include <set>
8#include <map>
9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
1using namespace std;
2const double eps = 1E-8;
3const int dx4[4]={1,0,0,-1};
4const int dy4[4]={0,-1,1,0};
5const int inf = 0x3f3f3f3f;
6string ori,tar;
7int main()
8{
9 #ifndef ONLINE_JUDGE
10 freopen("code/in.txt","r",stdin);
11 #endif
12 cin>>ori>>tar;
13 int p = ori.find(tar);
14 int ans = 0 ;
15 int lst = 0;
16 while (p!=-1)
17 {
18 ans++;
19 ori[p]='#';
20 lst = p + tar.length()-1;
21 ori[lst]='#';
1 p = ori.find(tar,lst);
2 }
3 cout<<ans<<endl;
1 #ifndef ONLINE_JUDGE
2 fclose(stdin);
3 #endif
4 return 0;
5}