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. 超简便安装mysql

    CentOS7默认数据库是mariadb,配置等用着不习惯,因此决定改成mysql,但是CentOS7的yum源中默认好像是没有mysql的.为了解决这个问题,我们要先下载mysql的repo源. 1 ...

  2. GO-指针与函数

    一.指针类型 1.普通类型,变量存的就是值,也叫值类型.指针类型存的是地址 2.获取变量的地址,用&,比如:var a int, 获取a的地址 &a 3.指针类型,变量存的是一个地址, ...

  3. 【转载】C#异常Retry通用类

    //Retry机制 public static class Retry { /// <summary> /// 重试零个参数无返回值的方法 /// </summary> /// ...

  4. tyvj P1050 最长公共子序列

    题目链接:http://tyvj.cn/p/1050 题解: 裸题,只是为了测试LCS模板写对没有…… #include<cstdio> #include<cstring> # ...

  5. 关于一些对location认识的误区

    1. location 的匹配顺序是“先匹配正则,再匹配普通”. 矫正: location 的匹配顺序其实是“先匹配普通,再匹配正则”.我这么说,大家一定会反驳我,因为按“先匹配普通,再匹配正则”解释 ...

  6. Tutorial 1: Serialization

    转载自:http://www.django-rest-framework.org/tutorial/1-serialization/#tutorial-1-serialization Tutorial ...

  7. hive的窗口函数ntile、row_number、rank

    一.ntile 序列函数不支持window子句 数据准备: cookie1,--, cookie1,--, cookie1,--, cookie1,--, cookie1,--, cookie1,-- ...

  8. 【hdoj_1250】Hat's Fibonacci(大数)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1250 思路:本题的Fibonacci数列是扩展的四阶的Fibonacci数列,用递推关系式求解即可. 题目 ...

  9. [loj2116]「HNOI2015」开店 动态点分治

    4012: [HNOI2015]开店 Time Limit: 70 Sec  Memory Limit: 512 MBSubmit: 2452  Solved: 1089[Submit][Status ...

  10. 修改 jupyter notebook 启动工作路径的方法

    Windows下jupyter notebook默认的启动路径就是当前cmd启动jupyter 的路径: C:\Users\用户名>jupyter notebook 此时jupyter 的启动工 ...