leetcode811
class Solution {
public:
void SplitString(const string& s, vector<string>& v, const string& c)
{
string::size_type pos1, pos2;
pos2 = s.find(c);
pos1 = ;
while (string::npos != pos2)
{
v.push_back(s.substr(pos1, pos2 - pos1));
pos1 = pos2 + c.size();
pos2 = s.find(c, pos1);
}
if (pos1 != s.length())
v.push_back(s.substr(pos1));
}
vector<string> subdomainVisits(vector<string>& cpdomains) {
vector<string> X;
map<string, int> MAP;
for (auto cpdomain : cpdomains)
{
vector<string> v1;
SplitString(cpdomain, v1, " ");//将访问数字和域名分开
int count = atoi(v1[].c_str());
string domain = v1[];
vector<string> v2;
SplitString(domain, v2, ".");
string last = "";
for (int i = v2.size() - ; i >= ; i--)
{
if (last == "")
{
last = v2[i];
}
else
{
last = v2[i] + "." + last;
}
if (MAP.find(last) != MAP.end())//找到了此项目
{
MAP[last] += count;
}
else//未有此项
{
MAP.insert(make_pair(last, count));
}
}
}
for (auto m : MAP)
{
string x = m.first;
stringstream ss;
ss << m.second;
string ct = ss.str();
X.push_back(ct + " " + x);
}
return X;
}
};
leetcode811的更多相关文章
- [Swift]LeetCode811. 子域名访问计数 | Subdomain Visit Count
A website domain like "discuss.leetcode.com" consists of various subdomains. At the top le ...
- Leetcode811.Subdomain Visit Count子域名访问计数
一个网站域名,如"discuss.leetcode.com",包含了多个子域名.作为顶级域名,常用的有"com",下一级则有"leetcode.com ...
随机推荐
- IIC时序图
- shell编程学习2
1.shell中调用linux命令(1)直接执行(2)反引号括起来执行.有时候我们在shell中调用linux命令是为了得到这个命令的返回值(结果值),这时候就适合用一对反引号(键盘上ESC按键下面的 ...
- nivicat premium连接阿里云数据库
1.首先打开Navicat,文件>新建连接>MySQL连接,其他的如一图所示 其中: 连接名:自己取一个名字 主机名:填写mysql的地址 用户名:mysql的登录的用户名 密码:登录的密 ...
- java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/xiaozao_web]]
二月 20, 2017 11:30:28 上午 org.apache.tomcat.util.digester.SetPropertiesRule begin警告: [SetPropertiesRul ...
- Today is weekend不是应该一定会输出吗
判断语句 If…else块,请看下面这个例子: <%! int day = 3; %> //声明变量感叹号 <html> <head><title>IF ...
- Node.js 问题集合
使用node合并多个接口, 最后获取数据慢的问题 暂时没解决方法 pm2 访问 ip 记录到日志 ...
- 接口取不到POST参数
利用类似httprequester小工具调试API时偶尔出现一直取不到POST的数据 解决方式: 1.$_POST['paramName']: 只能接收Content-Type: applicatio ...
- Juint 单元测试(2)
单元测试(junit testing),是指对软件中的最小可测试单元进行检查和验证.Java里单元指一个类. JUnit ,是一个开源的Java单元测试框架,是 Java的标准单元测试库,是非常重要第 ...
- 使用flowable 6.1.2 REST API 运行请假审批流程
一.下载 flowable rest war 包 http://download.csdn.net/detail/teamlet/9913312 二.部署 复制flowable REST.war到To ...
- C++纯虚函数实现
纯虚函数就是一个在基类中的虚函数,差别只是在一般的虚函数声明的后面加了"=0",虚函数允许函数通过与函数体之间的联系在运行时才建立,也就是在运行时才决定如何动作,称为运行时的多态性 ...