码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces - 625B 贪心

时间:2017-12-09 15:50:29      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:substr   int   while   end   sub   main   不重复   its   字符   

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

#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;
    }
}

Codeforces - 625B 贪心

标签:substr   int   while   end   sub   main   不重复   its   字符   

原文地址:http://www.cnblogs.com/caturra/p/8011551.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!