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