要求给定一串字符,并给定若干字符,求给定的一串字符中每个单词出现的次数

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+50;
char ch[maxn];
char txt[maxn];
map<string,int>mp;
vector<string>ss;
int tot=0;
void gettxt()
{
    string s;
    for(int i=0;i<strlen(txt);i++)
    {
        if(txt[i]==' ')
        {
            if(s.size())
            {
                transform(s.begin(), s.end(), s.begin(), ::tolower);
                mp[s]=0;
                ss.push_back(s);
            }
            s.clear();
        }
        else
        {
            s+=txt[i];
        }
    }
    if(s.size())
    {
         mp[s]=0;
        ss.push_back(s);
    }
}
int main()
{
    gets(txt);
    //puts(txt);
    gettxt();
    string s;
    while(cin>>s)
    {
        transform(s.begin(), s.end(), s.begin(), ::tolower);
        if(mp.count(s))
        mp[s]++;
    }
    for(int i=0;i<ss.size();i++)
    {
        cout<<ss[i]<<" "<<mp[ss[i]]<<endl;
    }
    return 0;
}