触宝内推-substring-c++

2017-09-06  本文已影响0人  Jacinth

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <unordered_map>
using namespace std;

int main()
{
    int n;
    while (cin >> n)
    {
        vector<string> strLib;
        for (int i = 0; i < n; ++i)
        {
            string str;
            cin >> str;
            strLib.push_back(str);//字符串之后插入一个字符
        }
        int m;
        cin >> m;
        for (int i = 0; i < m; ++i)
        {
            string query;
            cin >> query;
            int cnt = 0;
            for (auto str : strLib)
            {
                if (str.find(query) != string::npos)//查找字符串str是否包含子串query
                    cnt++;
            }
            cout << cnt << endl;
        }
    }
    return 0;
}

push_back使用方法
C++中string.find()函数与string::npos

上一篇下一篇

猜你喜欢

热点阅读