c++ - 如何按流行顺序输出子字符串的频率?
问题描述
我有一个接受电子邮件地址列表的程序,并且我正在尝试按其受欢迎程度的顺序输出这些域。该程序从用户那里获取输入,然后输出插入了多少个域。这是我的程序:
#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;
}
任何帮助将非常感激。
解决方案
推荐阅读
- azure-blob-storage - Azure IoT Edge 模块日志 - 任务上传日志因错误而失败
- oracle - 通过codeignier将时间戳类型数据插入Oracle数据库
- typescript - Svelte TypeScript:向事件处理程序添加类型时出现意外的 tokensvelte(parse-error)
- java - Zabbix 和 JMX 连接被拒绝
- pyomo - Pyomo 无法在抽象 Set 构建之前对其进行迭代
- python - Python apscheduler 变量从后台计划任务到瓶子
- html - 如何在尊重原始布局的下拉菜单中设置固定位置?
- elasticsearch - 更新成本与在弹性搜索中插入
- php - 未在此服务器上找到新的联系表无效 URL
- ios - tel:// 方案自动格式化电话号码