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中 ...
随机推荐
- Flask框架 之 路由和视图详解
路由+视图 我们之前了解了路由系统是由带参数的装饰器完成的. 路由本质:装饰器和闭包实现的. 路由设置的两种方式 来看个例子. @app.route('/index') def index(): re ...
- 防止SQL注入方法总结
一.参数化SQL 是指在设计与数据库链接并访问数据时,在需要填入数值或数据的地方,使用参数 (Parameter) 来给值,用@来表示参数. 在使用参数化查询的情况下,数据库服务器不会将参数的内容视为 ...
- VUE实战项目-数据转换之道
前言 公司的这个项目从去年底启动.至今经历winform版本与当前的VUE两个版本,前后经历不足3个月的时间.从纯技术角度来看,推进速度都很优异.究其原因,大抵我们都是喜欢“偷懒”的程序员,把能封装. ...
- Linux相关常用工具
Xshell Xshell可以在Windows界面下用来访问远端不同系统下的服务器,从而比较好的达到远程控制终端的目的. 通常需要通过vpn访问.建立vpn隧道可以通过FortiClient 或者 I ...
- 第06章-渲染Web视图
1. 理解视图解析 将控制器中请求处理的逻辑和视图中的渲染实现解耦是Spring MVC的一个重要特性.如果控制器中的方法直接负责产生HTML的话,就很难在不影响请求处理逻辑的前提下,维护和更新视图. ...
- telerik 值得学习 web mvc 桌面 控件大全
http://www.telerik.com http://www.dxper.net/forum-70-1.html http://www.dxper.net/forum.php
- SNMP协议学习笔记
什么是SNMP协议? SNMP协议是以UDP为基础的应用层协议,全称为 简单网络管理协议,用于网络管理系统与被管设备(路由器,交换机,服务器等设备)进行通信. 应用场景 随着网络设备的增多,需要单独的 ...
- ASP.NET Core依赖注入最佳实践,提示&技巧
分享翻译一篇Abp框架作者(Halil İbrahim Kalkan)关于ASP.NET Core依赖注入的博文. 在本文中,我将分享我在ASP.NET Core应用程序中使用依赖注入的经验和建议. ...
- c++最短路经典问题
一提起最短路,各位oier会想到什么呢? floyd,spfa,dij,或是bellman-ford? 其实,只要学会一种算法,大部分最短路问题就能很快解决了. 他就是堆优化的dijkstra. 首先 ...
- CentOS7 搭建 python pypi 私有源
(1)寻找可用的同步源,我选择的是中科大的源:http://rsync.mirrors.ustc.edu.cn (2)创建数据同步目录:/root/pypi(如果想存放到其他目录,可以通过软链接的方式 ...