首页 > 解决方案 > 如何按流行顺序输出子字符串的频率?

问题描述

我有一个接受电子邮件地址列表的程序,并且我正在尝试按其受欢迎程度的顺序输出这些域。该程序从用户那里获取输入,然后输出插入了多少个域。这是我的程序:

#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;


    }

任何帮助将非常感激。

标签: c++string

解决方案


推荐阅读