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. CF547D Mike and Fish

    欧拉回路,巧妙的解法. 发现每一个点$(x, y)$实际上是把横坐标和$x$和纵坐标$y$连一条线,然后代进去跑欧拉回路,这样里一条边对应了一个点,我们只要按照欧拉回路间隔染色即可. 注意到原图可能并 ...

  2. Part10-C语言环境初始化-一跃进入C大门lesson3

    1.跳转到c代码 因为内存中的代码来自于垫脚石SRAM,他们是相同的. 采用绝对跳转方式来完成. 因为我们是从汇编代码跳转到c语言的程序,所以我们要提前准备一个main.c文件. 修改makefile ...

  3. [原创]编译CLANG时遇到问题的解决办法

    CLANG备忘录: 1.编译时遇到 LINK1123 错误尝试使用其他版本的VS编译,可以有效解决这个问题 2.编译时遇到 Unexpectedfailure executing llvm-build ...

  4. linux学习1----初涉linux

    linux因其稳定高效的特点,受到很多开发者的青睐,因此将其作为服务器的操作系统. 作为一名开发者,程序员,掌握了一定的linux知识和技巧,程序的开发部署和运行也有不小的帮助. linux由于其开源 ...

  5. Java 线程不安全问题分析

    当多个线程并发访问同一个资源对象时,可能会出现线程不安全的问题 public class Method implements Runnable { private static int num=50; ...

  6. [算法基础]Big O Notation时间复杂度计算方法

    首先一点就是无视任何常量 从最简单的开始 statement; 这段时间复杂度为常数1,所以O(1). 然后 ; i < N; i++ ) statement; 这一段是线性的,则时间复杂度为N ...

  7. Extjs Hello extjs

    <html > <head runat="server"> <title></title> <link rel="s ...

  8. 【C#】CLR内存那点事(高级)

    对于这篇,不想再对值类型进行讨论,如要看值类型的内存怎么玩可以看一下(CLR内存那点事 初级),我们这篇主要讨论一下引用类型. 先来装备两个类 internal class Employee { pu ...

  9. 微信运动数据抓取(Python)

    "微信运动"能够向朋友分享一个包含有运动数据的网页,网页中就有我们需要的数据.url类似于:http://hw.weixin.qq.com/steprank/step/person ...

  10. .NET平台的资源文件管理

    可以管理文本.图片等不同类型的资源 管理方式(增删改) 可以直接修改XXX.resx源文件(XML格式,文本直接管理内容,图片需要指定路径,资源名和图片名可以不同) 也可以在VS的可视化界面上进行操作 ...