CROC 2016 - Qualification C. Hostname Aliases map
C. Hostname Aliases
题目连接:
http://www.codeforces.com/contest/644/problem/C
Description
There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.
You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://[/], where:
— server name (consists of words and maybe some dots separating them),
/ — optional part, where consists of words separated by slashes.
We consider two to correspond to one website if for each query to the first there will be exactly the same query to the second one and vice versa — for each query to the second there will be the same query to the first one. Take a look at the samples for further clarifications.
Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.
Please note, that according to the above definition queries http:// and http:/// are different.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://[/], where:
consists of lowercase English letters and dots, there are no two consecutive dots, doesn't start or finish with a dot. The length of is positive and doesn't exceed 20.
consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, doesn't start with a slash and its length doesn't exceed 20.
Addresses are not guaranteed to be distinct.
Output
First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one.
Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order.
Sample Input
10
http://abacaba.ru/test
http://abacaba.ru/
http://abacaba.com
http://abacaba.com/test
http://abacaba.de/
http://abacaba.ru/test
http://abacaba.de/test
http://abacaba.com/
http://abacaba.com/t
http://abacaba.com/test
Sample Output
1
http://abacaba.de http://abacaba.ru
Hint
题意
现在给你n个网站地址,这个网站地址包括域名和他的子地址
然后如果有两个网站的子地址都是一样的话,那么就说明这两个网站其实是一样的
现在问你一共有多少个一样的网址,输出出来。
题解:
可以hash,但是这道题卡单hash哦
其实我们可以用map乱搞一波……
先存每个域名的子地址集
然后再通过子地址集存每一个域名就好了。
代码
#include<bits/stdc++.h>
using namespace std;
map<string,vector<string> >mp;
map<vector<string>,vector<string> >ans;
int main()
{
int n;scanf("%d",&n);
for(int i=0;i<n;i++)
{
string s;
cin>>s;
s=s.substr(7)+'/';
int pos = s.find_first_of('/');
mp[s.substr(0,pos)].push_back(s.substr(pos));
}
for(auto &p:mp)
{
sort(p.second.begin(),p.second.end());
p.second.erase(unique(p.second.begin(),p.second.end()),p.second.end());
ans[p.second].push_back(p.first);
}
int tot = 0;
for(auto &p:ans)
if(p.second.size()>1)
tot++;
printf("%d\n",tot);
for(auto &p:ans)
{
if(p.second.size()>1)
{
for(auto &t:p.second)
cout<<"http://"<<t<<" ";
cout<<endl;
}
}
}
CROC 2016 - Qualification C. Hostname Aliases map的更多相关文章
- CROC 2016 - Qualification B. Processing Queries 模拟
B. Processing Queries 题目连接: http://www.codeforces.com/contest/644/problem/B Description In this prob ...
- Python之Dijango的“坑” hostname, aliases, ipaddrs = gethostbyaddr(name) UnicodeDecodeError: 'utf-8' cod
错误代码提示: hostname, aliases, ipaddrs = gethostbyaddr(name) UnicodeDecodeError: 'utf-8' codec can't dec ...
- VK Cup 2016 - Qualification Round 1——A. Voting for Photos(queue+map)
A. Voting for Photos time limit per test 1 second memory limit per test 256 megabytes input standard ...
- VK Cup 2016 - Qualification Round 1——B. Chat Order(试手stack+map)
B. Chat Order time limit per test 3 seconds memory limit per test 256 megabytes input standard input ...
- codeforces 589A Email Aliases(map)
Description Polycarp has quite recently learned about email aliases. Of course, he used to suspect t ...
- CF CROC 2016 Intellectual Inquiry
题目链接:http://codeforces.com/contest/655/problem/E 大意是Bessie只会英文字母表中的前k种字母,现在有一个长度为m+n的字母序列,Bessie已经知道 ...
- CF #CROC 2016 - Elimination Round D. Robot Rapping Results Report 二分+拓扑排序
题目链接:http://codeforces.com/contest/655/problem/D 大意是给若干对偏序,问最少需要前多少对关系,可以确定所有的大小关系. 解法是二分答案,利用拓扑排序看是 ...
- CROC 2016 - Elimination Round (Rated Unofficial Edition) D. Robot Rapping Results Report 二分+拓扑排序
D. Robot Rapping Results Report 题目连接: http://www.codeforces.com/contest/655/problem/D Description Wh ...
- VK Cup 2016 - Qualification Round 1 (Russian-Speaking Only, for VK Cup teams) B. Chat Order 水题
B. Chat Order 题目连接: http://www.codeforces.com/contest/637/problem/B Description Polycarp is a big lo ...
随机推荐
- Django 1.10中文文档-第一个应用Part7-自定义管理站点
开发第一个Django应用,Part7 本教程上接Part6.将继续完成这个投票应用,本节将着重讲解如果用Django自动生成后台管理网站. 自定义管理表单 通过admin.site.register ...
- linux中的计算【转】
shell中的赋值和操作默认都是字符串处理,在此记下shell中进行数学运算的几个特殊方法,以后用到的时候可以来看,呵呵 1.错误方法举例 a) var=1+1 echo $var 输出的结果是1+1 ...
- 用Centos7搭建小微企业Samba文件共享服务器【转】
转自 用Centos7搭建小微企业Samba文件共享服务器 - 今日头条(www.toutiao.com)http://www.toutiao.com/i6436937837660078593/ 最近 ...
- [ python ] 字典的使用
数据类型划分: 可变数据类型:list.dict.set 不可哈希 不可变数据类型:tuple.bool.int.str 可哈希 字典 python内置了字典类型,使用键-值( ...
- yolo回归型的物体检测
本弱又搬了另外一个博客的讲解: 缩进YOLO全称You Only Look Once: Unified, Real-Time Object Detection,是在CVPR2016提出的一种目标检测算 ...
- 深度学习方法(九):自然语言处理中的Attention Model注意力模型
欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.NET/xbinworld. 技术交流QQ群:433250724,欢迎对算法.技术感兴趣的同学加入. 上一篇博文深度学习方法(八):Enc ...
- css3 图标变大变小在变小变大
css3 @-webkit-keyframes anLoca { from { -webkit-transform: scale3d(1, 1, 1); } to { -webkit-transfor ...
- TPC-H数据导入MySQL教程
0. TPC-H是啥 TPC-H是TPC提供的一个benchmark,用来模拟一个现实中的商业应用,可以生成一堆虚构的数据,且自带一些查询,可以导入到各种数据库中来模拟现实需求,检查性能. 具体是怎样 ...
- 面试题12:打印1到最大的n位数(大数问题)
面试题是关于n位整数并且没有限定n的取值范围,或者是输入任意大小的整数,那么这个题目就很可能需要考虑大数问题.字符串是一个简单的.有效的表示大数的方法 这题比较难,用递归表达全排列,数字每一位都可能是 ...
- 【企业通讯录app番外篇】怎么样创建服务端?
本文将指导大家如何去创建企业通讯录app的服务端 除了获取图片,客户端与服务端唯一的交互就是获取最新数据,如果该用户不能获取数据(用户名密码错误.用户离职被删)则返回空. 1:典型的交互流程如下: 用 ...