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 ...
随机推荐
- jQuery对select操作
(转自:http://www.cnblogs.com/as285996985/articles/1535014.html) //遍历option和添加.移除optionfunction changeS ...
- windows下memcached安装以及php_memcache.dll扩展
http://kimi.it/258.html http://kimi.it/259.html https://www.cnblogs.com/elenaPeng/p/6877530.html htt ...
- 剑指offer--29.从上往下打印二叉树
层序遍历,队列 ------------------------------------------------------------------------------------- 时间限制:1 ...
- 【python】命令行解析工具argparse用法
python的命令行参数 之前有用到optget, optparse, 现在这些都被弃用了. import argparse parser = argparse.ArgumentParser() ar ...
- Mac上安装Jenkins持续部署初体验
1.首先去官网下载安装包 https://jenkins.io/doc/book/installing/ 安装完成后,很不幸,无法访问他的默认站点 查了一堆资料,有的说环境变量没有配置,有的说没有执行 ...
- 2018下C程序设计(上)第0次作业
1.翻阅邹欣老师博客关于师生关系博客,并回答下列问题: (1)大学和高中最大的不同是什么?请看大学理想的师生关系是?有何感想? 我认为大学和高中最大的不同在于我们(包括老师)对学习的态度.在高中,学生 ...
- Python学习-数据运算
在Python中有丰富的算术运算,这使得Python在科学计算领域有着很高的地位,Python可以提供包括四则运算在内的各种算术运算. a = 10 b = 20 print(a-b) #-10 pr ...
- 剑指offer-第七章面试案例1(字符串转换为整型)
//将字符串转换为整型 //思路:特殊的输入测试: //1,考虑字符串是否为空.2.字符串问空的时候的返回0,和真实的返回0直键的区别.3,字符串中出现0~9的字符处理 //4.字符串中出现*,¥等一 ...
- LeetCode Design Log Storage System
原题链接在这里:https://leetcode.com/problems/design-log-storage-system/description/ 题目: You are given sever ...
- 转载 基于NicheStack协议栈的TCP/IP实现
一.摘要 Altera软件NIOS II高版本(7.2版本以上,本例程中使用的是9.0版本)中实现TCP/IP所用的协议栈为NicheStack,常用的例程有2个,web_server和simple_ ...