您好,欢迎来到尔游网。
搜索
您的当前位置:首页统计子序列出现个数(C++)

统计子序列出现个数(C++)

来源:尔游网

描述

代码

#include <iostream>
#include <map>

using namespace std;

map<string, int> m;


int main() {


    
    
    string dict, subDict, input;
    while (getline(cin, dict) && dict[0] != '\0') {
        for (int i = 1; i <= dict.size(); ++i) {
            subDict = dict.substr(0, i);
            m[subDict] += 1;
        }
    }
    string res;
    while (getline(cin, input) && input[0] != '\0') {
        res += to_string(m[input]);
        res += '\n';
    }
    cout << res;



    
    return 0;
}


结果

// 输入:
// banana
// band
// acm
// absolute
// bee
//
// ba
// b
// band
// abc

// 输出:
// 2
// 3
// 1
// 0

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- axer.cn 版权所有 湘ICP备2023022495号-12

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务