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中 ...
随机推荐
- Django-项目上线后,静态文件配置失效以及404、500页面的全局配置
https://blog.csdn.net/Jamin2018/article/details/79060509 https://www.cnblogs.com/lfoder/p/6013142.ht ...
- cinder create volume的流程(1)
前提:代码的跟踪,使用的是ocata版本 零.执行cinder create 命令,创建数据卷,打开debug开关 [root@osnode241001 ~]# cinder --debug crea ...
- 钩子(hook)编程
一.钩子介绍 1.1钩子的实现机制 钩子英文名叫Hook,是一种截获windows系统中某应用程序或者所有进程的消息的一种技术.下图是windows应用程序传递消息的过程: 如在键盘中按下一键,操作系 ...
- SKU:唯一标识填什么
策略 随意填写 只要别和别人重复就好 ,不过重复你也创建不了. 最好填与APP信息相关的,比如直接填写bundle ID 上去...跟套装ID保持一致. 你新建应用的时候都还没有APP ID 你怎么填 ...
- Selenium辅助工具
下载Firefox39.0版本浏览器,安装firebug和FirePath.最新版的Firefox在扩展组件中无法找到firebug,可以使用旧的版本的Firefox浏览器. FirePath插件的使 ...
- pycharm设置连接
https://blog.csdn.net/u013088062/article/details/50100121
- MySQL中查询时对字母大小写的区分
我相信很多人在mysql中查询时都遇到过mysql不区分字母大小写的情况:如以下例子: 1.SELECT * FROM `user` WHERE userpass = 'Z20'; 结果为: 2.SE ...
- 如果plsql连接没问题,但程序中报ORA-12504的错误
说明程序中配置数据库连接的地方没有写tnsnames.ora中的SERVICE_NAME,或者SERVICE_NAME写的有错,检查一下,改正应该就好了
- C# Winform下一个热插拔的MIS/MRP/ERP框架12(数据处理基类)
作为ERP等数据应用程序,数据库的处理是重中之重. 在框架中,我封装了一个数据库的基类,在每个模组启动或窗体启动过程中,实例化一个基类即可调用CRUD操作(create 添加read读取 update ...
- 【ARC083E】Bichrome Tree 树形dp
Description 有一颗N个节点的树,其中1号节点是整棵树的根节点,而对于第ii个点(2≤i≤N)(2≤i≤N),其父节点为PiPi 对于这棵树上每一个节点Snuke将会钦定一种颜色(黑或白), ...