487-3279

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 309235   Accepted: 55223

Description

Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or phrase. For example, you can call the University of Waterloo by dialing the memorable TUT-GLOP. Sometimes only part of the number is used to spell a word. When you get back to your hotel tonight you can order a pizza from Gino's by dialing 310-GINO. Another way to make a telephone number memorable is to group the digits in a memorable way. You could order your pizza from Pizza Hut by calling their ``three tens'' number 3-10-10-10.

The standard form of a telephone number is seven decimal digits with a hyphen between the third and fourth digits (e.g. 888-1200). The keypad of a phone supplies the mapping of letters to numbers, as follows:

A, B, and C map to 2 
D, E, and F map to 3 
G, H, and I map to 4 
J, K, and L map to 5 
M, N, and O map to 6 
P, R, and S map to 7 
T, U, and V map to 8 
W, X, and Y map to 9

There is no mapping for Q or Z. Hyphens are not dialed, and can be added and removed as necessary. The standard form of TUT-GLOP is 888-4567, the standard form of 310-GINO is 310-4466, and the standard form of 3-10-10-10 is 310-1010.

Two telephone numbers are equivalent if they have the same standard form. (They dial the same number.)

Your company is compiling a directory of telephone numbers from local businesses. As part of the quality control process you want to check that no two (or more) businesses in the directory have the same telephone number.

Input

The input will consist of one case. The first line of the input specifies the number of telephone numbers in the directory (up to 100,000) as a positive integer alone on the line. The remaining lines list the telephone numbers in the directory, with each number alone on a line. Each telephone number consists of a string composed of decimal digits, uppercase letters (excluding Q and Z) and hyphens. Exactly seven of the characters in the string will be digits or letters.

Output

Generate a line of output for each telephone number that appears more than once in any form. The line should give the telephone number in standard form, followed by a space, followed by the number of times the telephone number appears in the directory. Arrange the output lines by telephone number in ascending lexicographical order. If there are no duplicates in the input print the line:

No duplicates.

Sample Input

12
4873279
ITS-EASY
888-4567
3-10-10-10
888-GLOP
TUT-GLOP
967-11-11
310-GINO
F101010
888-1200
-4-8-7-3-2-7-9-
487-3279

Sample Output

310-1010 2
487-3279 4
888-4567 3
两个map
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<map>
#include<set>
#define ll long long
using namespace std;
map<char,char>m;
map<string,int>mm;
string s,ss;
int n;
int main()
{
m['A']='',m['B']='',m['C']='',m['D']='',m['E']='';
m['F']='',m['G']='',m['H']='',m['I']='',m['J']='';
m['K']='',m['L']='',m['M']='',m['N']='',m['O']='';
m['P']='',m['R']='',m['S']='',m['T']='',m['U']='';
m['V']='',m['W']='',m['X']='',m['Y']='';
cin>>n;
while(n--)
{
cin>>s;
int cnt=;
for(int i=;s[i];i++)
{
if(s[i]=='-')
continue;
else
{
cnt++;
if(m.count(s[i])==)
ss=ss+s[i];
else
ss=ss+m[s[i]];
if(cnt==)
ss=ss+'-';
}
}
mm[ss]++;
ss.clear();
}
int x,flag=;
map<string,int>::iterator it;
for(it=mm.begin();it!=mm.end();it++)
{
x=it->second;
if(x>)
{
cout<<it->first<<' '<<x<<endl;
flag=;
}
}
if(flag==)
cout<<"No duplicates."<<endl;
return ; }
字典树
//poj1002
#include<iostream>
#include <map>
#include <cstdio>
#include<string.h>
using namespace std;
map<char, char> m;
int id, len, root, pos = , k;
int flag=;
int trie[][], vis[];
char s[], s1[],str[];
void insert(char *s1)
{ root = ;
for (int i = ; i<k; i++)
{
int id = s1[i]-'';
if (!trie[root][id])
trie[root][id] = pos++;
root = trie[root][id];
}
vis[root]++;//标记输入一串字符串的最后一个字符,顺便统计每一个单词出现的次数 }
void dfs(int root, int deep)
{
for (int i = ; i <= ; i++)
{ if (trie[root][i])
{
str[deep] = i+'';
if (vis[trie[root][i]]>=)
{
str[deep + ] = '\0';
for(int j=;j<;j++)
cout<<str[j];
cout<<'-';
for(int j=;j<;j++)
cout<<str[j];
cout << ' ' << vis[trie[root][i]] << endl;
flag=;
}
dfs(trie[root][i], deep + );
} } }
int main()
{
int n; m['A'] = m['B'] = m['C'] = '';
m['D'] = m['E'] = m['F'] = '';
m['G'] = m['H'] = m['I'] = '';
m['J'] = m['K'] = m['L'] = '';
m['M'] = m['N'] = m['O'] = '';
m['P'] = m['R'] = m['S'] = '';
m['T'] = m['U'] = m['V'] = '';
m['W'] = m['X'] = m['Y'] = ''; while (scanf("%d", &n) != EOF)
{
memset(vis, , sizeof(vis));
for (int i = ; i < n; i++)
{
scanf("%s", s);
len = strlen(s);
k = ;
for (int i = ; i<len; i++)
{
if (s[i] == '-')
continue;
else if (s[i] >= 'A'&&s[i] <= 'Y'&&s[i] != 'Q')
{
s1[k] = m[s[i]];
k++;
}
else
{
s1[k] = s[i];
k++;
}
}
insert(s1);
}
dfs(, );
if(flag==)
cout<<"No duplicates."<<endl;
}
return ;
}

poj1002 字典树+map+查询单词出现次数的更多相关文章

  1. ZOJ 3674 Search in the Wiki(字典树 + map + vector)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4917 题意:每一个单词都一些tips单词. 先输入n个单词和他们的t ...

  2. ACM学习历程—HDU 4287 Intelligent IME(字典树 || map)

    Description We all use cell phone today. And we must be familiar with the intelligent English input ...

  3. POJ 1002 487-3279(字典树/map映射)

    487-3279 Time Limit: 2000MS        Memory Limit: 65536K Total Submissions: 309257        Accepted: 5 ...

  4. I: Carryon的字符串排序(字典树/map映射)

    2297: Carryon的字符串 Time Limit: C/C++ 1 s      Java/Python 3 s      Memory Limit: 128 MB      Accepted ...

  5. HDU 1298 T9【字典树增加||查询】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1298 T9 Time Limit: 2000/1000 MS (Java/Others)    Memo ...

  6. hdoj 1251 字典树||map

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submi ...

  7. 字典树+map

    Problem Description Carryon最近喜欢上了一些奇奇怪怪的字符,字符都是英文小写字母,但奇怪的是a可能比b小,也可能比b大,好奇怪.与此同时,他拿到了好多的字符串,可是看着很不顺 ...

  8. HDU1251 统计难题(字典树|map

    Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀). Input输入数据的第一部分 ...

  9. STL MAP及字典树在关键字统计中的性能分析

    转载请注明出处:http://blog.csdn.net/mxway/article/details/21321541 在搜索引擎在通常会对关键字出现的次数进行统计,这篇文章分析下使用C++ STL中 ...

随机推荐

  1. MYSQL优化——索引覆盖

    索引覆盖:如果查询的列恰好是索引的一部分,那么查询只需要在索引文件上进行,不需要进行到磁盘中找数据,若果查询得列不是索引的一部分则要到磁盘中找数据. 建表: create table test_ind ...

  2. Django----解决跨域

    cors(跨域资源共享): 本质设置响应头 定制中间件 cors.py 后在settings.py中间件中配置 from django.utils.deprecation import Middlew ...

  3. python3安装 feedparser

    在看<集体智慧编程>时碰到python3环境下安装feedparser的问题,搜索发现很多人碰到此问题,最终找以下方法解决. how to install feedparser on py ...

  4. Http中的身份传递

    IIS默认的身份验证方式 身份传递策略包括使用操作系统的委派功能或在应用程序级传递票证和/或凭证 为了阻止IIS的身份验证委派,可以在web.config加入如下设置, <system.web& ...

  5. Haar-like feature和Haar wavelet

    Haar-like features are digital image features used in object recognition. They owe their name to the ...

  6. c# Include 与 用户控件

    <!-- #Include File="~/App_UC/head.bootstrap.aspx --> 这个路径文件可以是你html代码,也可以是应用脚本文件, 原理:跟用户控 ...

  7. Java简单实现AOP,Java通用异常拦截,Java与Lamada

    直接看代码不废话.不懂Lamada直接百度... package test; /** * QQ:1448376744 * @author 花间岛 * */ //控制器 public class Con ...

  8. Mybatis 的动态 SQL 语句

    <if>标签 我们根据实体类的不同取值,使用不同的 SQL 语句来进行查询. 比如在 id 如果不为空时可以根据 id 查询, 如果 username 不同空时还要加入用户名作为条件.这种 ...

  9. 321. Create Maximum Number (c++ ——> lexicographical_compare)

    Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum numb ...

  10. LNMP(linux+nginx+mysql+php)服务器环境配置【转载】

    本文转载自 园友David_Tang的博客,如有侵权请联系本人及时删除,原文地址: http://www.cnblogs.com/mchina/archive/2012/05/17/2507102.h ...