poj1002 字典树+map+查询单词出现次数
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+查询单词出现次数的更多相关文章
- ZOJ 3674 Search in the Wiki(字典树 + map + vector)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4917 题意:每一个单词都一些tips单词. 先输入n个单词和他们的t ...
- ACM学习历程—HDU 4287 Intelligent IME(字典树 || map)
Description We all use cell phone today. And we must be familiar with the intelligent English input ...
- POJ 1002 487-3279(字典树/map映射)
487-3279 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 309257 Accepted: 5 ...
- I: Carryon的字符串排序(字典树/map映射)
2297: Carryon的字符串 Time Limit: C/C++ 1 s Java/Python 3 s Memory Limit: 128 MB Accepted ...
- HDU 1298 T9【字典树增加||查询】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1298 T9 Time Limit: 2000/1000 MS (Java/Others) Memo ...
- hdoj 1251 字典树||map
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- 字典树+map
Problem Description Carryon最近喜欢上了一些奇奇怪怪的字符,字符都是英文小写字母,但奇怪的是a可能比b小,也可能比b大,好奇怪.与此同时,他拿到了好多的字符串,可是看着很不顺 ...
- HDU1251 统计难题(字典树|map
Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀). Input输入数据的第一部分 ...
- STL MAP及字典树在关键字统计中的性能分析
转载请注明出处:http://blog.csdn.net/mxway/article/details/21321541 在搜索引擎在通常会对关键字出现的次数进行统计,这篇文章分析下使用C++ STL中 ...
随机推荐
- 网页中的foot底部定位问题
有时候,我们会碰到这样一个问题. 网页底部一般有个foot对吧,放置一些友情链接版权声明什么的,这个模块是如何定位的? 要是直接放内容区域的下面的话,假如是内容区域的高度不够的话,那么foot下面是会 ...
- Action Results in MVC
- JavaEE互联网轻量级框架整合开发(书籍)阅读笔记(3):常用动态代理之JDK动态代理、CGLIB动态代理
一.动态代理的理解 动态代理的意义在于生成一个占位(又称代理对象),来代理真实对象,从而控制真实对象的访问. 先来谈谈什么是代理模式. 假设这样一个场景:你的公司是一家软件 ...
- java代码实现顺序队列
java实现顺序队列 package xianxinTable; import java.util.ArrayList; import java.util.Iterator; import com.s ...
- SxsTrace使用的方法
Windows7平台上有一个强大的SxsTrace工具,可以跟踪调试应用程序运行时需要的动态库的版本和路径. SxsTrace使用的方法: 1.首先必须以Administrator用户身份登录 ...
- C语言/C++编程学习:C语言环境设置
C语言是面向过程的,而C++是面向对象的 C和C++的区别: C是一个结构化语言,它的重点在于算法和数据结构.C程序的设计首要考虑的是如何通过一个过程,对输入(或环境条件)进行运算处理得到输出(或实现 ...
- 解决golang windows调试问题:Could not determine version number: could not find symbol value for runtime.buildVersion
版本信息: go:1.8.3 windows: win7/64 idea-go-plugin:171.4694.61 在windows下,使用dlv进行调试的时候,如果golang程序引入了c模块,比 ...
- I-team 博客全文检索 Elasticsearch 实战
一直觉得博客缺点东西,最近还是发现了,当博客慢慢多起来的时候想要找一篇之前写的博客很是麻烦,于是作为后端开发的楼主觉得自己动手丰衣足食,也就有了这次博客全文检索功能Elasticsearch实战,这里 ...
- Quicksort------代码之美
#include<iostream> #include<cstdlib> #include<time.h> using namespace std; void sw ...
- C# 抽象
好多人将抽象类也作为多态的一种,其实我觉得并不是特别的好. 抽象在C#中是类的一种表现. 如果将类作为多态,那么前面所有的东西不就白费了吗? C#的 抽象很简单. 那就是抽象. 基本就是高度抽象. 那 ...