如何按流行度顺序输出子字符串的频率?

时间:2018-10-12 09:52:35

标签: c++ string

我有一个程序,该程序接受电子邮件地址列表,并且我尝试按域名的受欢迎程度进行输出。该程序从用户处获取输入,然后输出已插入多少个域。这是我的程序:

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main()
{
std::vector<std::string> addresses;
int count = 0;


    for (int i = 1; i <= 5; i++)
    {
        std::cout << "Insert an e-mail address " << std::endl;
        std::string address;
        if (!getline(std::cin, address) || address.empty())break;
        addresses.push_back(address);

        int pos = address.find("@");
        std::string sub = address.substr(pos + 1);

        while (pos != std::string::npos)
        {

            count++;
            pos = address.find("@", pos + 1);


        }


    }

        std::cout<<"Number of domains:"  << count << std::endl;


    }

任何帮助将不胜感激。

0 个答案:

没有答案