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的更多相关文章

  1. [Swift]LeetCode811. 子域名访问计数 | Subdomain Visit Count

    A website domain like "discuss.leetcode.com" consists of various subdomains. At the top le ...

  2. Leetcode811.Subdomain Visit Count子域名访问计数

    一个网站域名,如"discuss.leetcode.com",包含了多个子域名.作为顶级域名,常用的有"com",下一级则有"leetcode.com ...

随机推荐

  1. python练习题100例

    链接地址:http://www.runoob.com/python/python-100-examples.html

  2. 由PostgreSQL的区域与字符集说起(转)

    转自:http://blog.chinaunix.net/uid-354915-id-3502551.html 由PostgreSQL的区域与字符集说起 一.PostgreSQL的区域区域属性有以下几 ...

  3. 《Drools7.0.0.Final规则引擎教程》第3章 3.2 KIE API解析

    3.2.4 KieServices 该接口提供了很多方法,可以通过这些方法访问KIE关于构建和运行的相关对象,比如说可以获取KieContainer,利用KieContainer来访问KBase和KS ...

  4. 正则化项L1和L2的区别

    https://blog.csdn.net/jinping_shi/article/details/52433975 https://blog.csdn.net/zouxy09/article/det ...

  5. (四)java基本语法

    关键字 被java赋予了特殊意义的单词: class,new,private,protected,public,static,final,abstract,interface,this,super,I ...

  6. Android 发布Apk签名

    1.签名的意义 为了保证每个应用程序开发商合法ID,防止部分开放商可能通过使用相同的Package Name来混淆替换已经安装的程序,我们需要对我们发布的APK文件进行唯一签名,保证我们每次发布的版本 ...

  7. Python之struct

    struct是Python中的内建模块,用来在C语言中的结构体与Python中的字符串之间进行转换,数据一般来自文件或网络 1. 功能 (1) 按照指定格式将Python数据转换为字符串(该字符串为字 ...

  8. bzoj 3124 直径

    Written with StackEdit. Description 小\(Q\)最近学习了一些图论知识.根据课本,有如下定义. 树:无回路且连通的无向图,每条边都有正整数的权值来表示其长度.如果一 ...

  9. Git 下载、安装与SSH配置

    一.Git学习笔记(基于Github) Git简介 Git是目前流行的分布式版本管理系统.它拥有两套版本库,本地库和远程库,在不进行合并和删除之类的操作时这两套版本库互不影响.也因此其近乎所有的操作都 ...

  10. iOS6和iOS7代码的适配(5)——popOver

    popOver这个空间本身是iPad only的,所以iPhone上见不到,我记得微信上有个这样的弹出框,有扫一扫等几个菜单项,估计这是腾讯自己实现的,用于菜单的扩展. popOver从iOS6到iO ...