C++ 如何按流行程度的顺序输出子字符串的频率?
我有一个接受电子邮件地址列表的程序,我正试图按受欢迎程度的顺序输出这些域。程序从用户处获取输入,然后输出插入的域数。这是我的节目:C++ 如何按流行程度的顺序输出子字符串的频率?,c++,string,C++,String,我有一个接受电子邮件地址列表的程序,我正试图按受欢迎程度的顺序输出这些域。程序从用户处获取输入,然后输出插入的域数。这是我的节目: #include <iostream> #include <string> #include <vector> #include <algorithm> int main() { std::vector<std::string> addresses; int count = 0; for (i
#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;
}
#包括
#包括
#包括
#包括
int main()
{
向量地址;
整数计数=0;
对于(int i=1;i),您很可能正在寻找可以轻松计算频率的std::map