题解 | #子串计算#

子串计算

https://www.nowcoder.com/practice/bcad754c91a54994be31a239996e7c11

#include <iostream>
#include <map>
using namespace std;
int appearTimes(string x,string y){
    int i=0;
    int r=0;
    while(i<x.length()){
        if(x.find(y,i)==string::npos) break;
        else {
            i=x.find(y,i)+1;
            r++;
        }
    }
    return r;
}
map<string,int> times;
int main() {
    string x;
    while(cin>>x){
        times.clear();
        times["0"]=appearTimes(x, "0");
        times["1"]=appearTimes(x, "1");
        for(int i=0;i<x.length();i++){
            for(int j=2;i+j<=x.length();j++){
                string n=x.substr(i,j);
                times[n]=appearTimes(x, n);
            }
        }
        for(map<string,int>::iterator i=times.begin();i!=times.end();
        i++){
            if(i->second>1){
                cout<<i->first<<' '<<i->second<<endl;
            }
        }
    }
}

全部评论

相关推荐

人力小鱼姐:实习经历没有什么含金量,咖啡店员迎宾这种就别写了,其他两段包装一下 想找人力相关的话,总结一下个人优势,结合校园经历里有相关性的部分,加一段自我评价
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务