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

  1. CROC 2016 - Qualification B. Processing Queries 模拟

    B. Processing Queries 题目连接: http://www.codeforces.com/contest/644/problem/B Description In this prob ...

  2. Python之Dijango的“坑” hostname, aliases, ipaddrs = gethostbyaddr(name) UnicodeDecodeError: 'utf-8' cod

    错误代码提示: hostname, aliases, ipaddrs = gethostbyaddr(name) UnicodeDecodeError: 'utf-8' codec can't dec ...

  3. 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 ...

  4. 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 ...

  5. codeforces 589A Email Aliases(map)

    Description Polycarp has quite recently learned about email aliases. Of course, he used to suspect t ...

  6. CF CROC 2016 Intellectual Inquiry

    题目链接:http://codeforces.com/contest/655/problem/E 大意是Bessie只会英文字母表中的前k种字母,现在有一个长度为m+n的字母序列,Bessie已经知道 ...

  7. CF #CROC 2016 - Elimination Round D. Robot Rapping Results Report 二分+拓扑排序

    题目链接:http://codeforces.com/contest/655/problem/D 大意是给若干对偏序,问最少需要前多少对关系,可以确定所有的大小关系. 解法是二分答案,利用拓扑排序看是 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 商城项目(ssm+dubbo+nginx+mysql统合项目)总结(1)

    我不会在这里贴代码和详细步骤什么的,我觉得就算我把它贴出来,你们照着步骤做还是会出很多问题,我推荐你们去看一下黑马的这个视频,我个人感觉很不错,一步一步走下来可以学到很多东西.另外,视频和相关文档的话 ...

  2. ogg使用语句

    create tablespace ogg datafile '/oracle/oradata/DRMT/ogg01.dbf' size 50M autoextend on; edit params ...

  3. nginx配置不当导致的目录遍历下载漏洞-“百度杯”CTF比赛 2017 二月场

    题目:http://98fe42cede6c4f1c9ec3f55c0f542d06b680d580b5bf41d4.game.ichunqiu.com/login.php 题目内容: 网站要上线了, ...

  4. ubuntu 命令配置ip 网关 dns

    如果是在虚拟机中使用Ubuntu,先设置好主机的网络,然后配置虚拟机Ubuntu的IP和网关 如果主机操作系统就是Ubuntu,请直接参照下文进行设置 内容如下: 1. 检验是否可以连通,就使用pin ...

  5. eWebEditor复制粘贴图片时过滤域名

    1.找到form.js 路径:plugins/frame/scripts/form.js 这个方法: 2.替换这个方法 /** * 处理参数 */ Form.prototype.processReqP ...

  6. 常见的 JavaScript 内存泄露

    什么是内存泄露 指由于疏忽或错误造成程序未能释放已经不再使用的内存.内存泄漏并非指内存在物理上的消失, 而是应用程序分配某段内存后,由于设计错误,导致在释放该段内存之前就失去了对该段内存的控制,从而造 ...

  7. Ceph 时钟偏移问题 clock skew detected 解决方案--- 部署内网NTP服务

    告警:HEALTH_WARN clock skew detected on mon.ip-10-25-195-6; 8 requests are blocked > 32 sec; Monito ...

  8. hexdump related.

    hexdump format strings Tue 13 December 2005 In tips. Ian Wienand More from the "things you'd le ...

  9. 写在Web考试后的一点小总结

    在实验室折腾附加题折腾了一个多钟没做出来……晚上回到宿舍决定再试一试,按原来的思路居然行了,目测在实验室的时候什么地方打错字了吧(心在流血) 实现晃过元素后出现跟随鼠标的悬浮窗,只有几行代码给我折腾了 ...

  10. EF 剥坑

    1.简单 count 会生成不必要的嵌套 var xs = (from x in dbContext.db_API_Operationallog where x.id<1 select 1 ). ...