Codeforces - 625B 贪心

求最小不重复匹配次数
改最后一个字符最划算
我当时怎么就没看出来..

#include<bits/stdc++.h>
using namespace std;
string S,T;
int main(){
	while(cin>>S>>T){
		int ans=0;
		for(int i = 0; i < S.length();){
			if(T==S.substr(i,T.length())){
				ans++; 
				S[i+T.length()-1]='#';
				i=i+T.length();
			}
			else i++;
//			cout<<S<<endl;
		}
		cout<<ans<<endl;
	}
}
posted @ 2017-12-09 15:12  Caturra  阅读(179)  评论(0)    收藏  举报