POJ 1002 487-3279(map映照容器的使用)
Description
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
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
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
- /*
- 问题 输入包含大写字母、-、数字的字符串,将其中的大写字母转换成对应的数字,即标准化后,将出现超过2次的号码标准的形式
- 按字典序输出。
- 解题思路 先将字符串存储,将其转化为标准形式存入map映照容器中,其中插入键值和映照数据是注意pair的使用,条件输出即可。
- */
- #include<cstdio>
- #include<string>
- #include<cctype>
- #include<cstring>
- #include<iostream>
- #include<vector>
- #include<algorithm>
- #include<map>
- using namespace std;
- struct phoneNumber{
- string num;
- int cou;
- }phoList[];
- int phocou;
- string conver(char *str);
- char aton(char a);
- void check(string str);
- map<string,int> m;
- int main()
- {
- int n,i;
- string temp;
- char str[];
- while(scanf("%d",&n) != EOF){
- for(i=;i<n;i++){
- scanf("%s",str);
- temp=conver(str);
- check(temp);
- }
- /*for(i=0;i<phocou;i++){
- cout<<phoList[i].num<<' '<<phoList[i].cou<<endl;
- }*/
- int flag=;
- map<string,int>::iterator it;
- for(it=m.begin();it != m.end(); it++){
- if(it->second > ){
- flag=;
- cout<<it->first<<' '<<it->second<<endl;
- }
- }
- if(!flag)
- cout<<"No duplicates.\n";
- }
- return ;
- }
- void check(string str)
- {
- map<string,int>::iterator it;
- it=m.find(str);
- if(it == m.end())
- m.insert( pair<string,int>(str,) );
- else
- it->second++;
- }
- string conver(char *str)
- {
- int len=strlen(str),i;
- string sum;
- for(i=;i<len;i++){
- if(isalpha(str[i])){
- sum = sum + aton(str[i]);
- }
- else if(isdigit(str[i])){
- sum = sum + str[i];
- }
- }
- string::iterator it=sum.begin();
- sum.insert(it + ,'-');
- //cout<<sum<<endl;
- return sum;
- }
- char aton(char a)
- {
- if(a == 'A' || a == 'B' || a == 'C')
- return '';
- if(a == 'D' || a == 'E' || a == 'F')
- return '';
- if(a == 'G' || a == 'H' || a == 'I')
- return '';
- if(a == 'J' || a == 'K' || a == 'L')
- return '';
- if(a == 'M' || a == 'N' || a == 'O')
- return '';
- if(a == 'P' || a == 'R' || a == 'S')
- return '';
- if(a == 'T' || a == 'U' || a == 'V')
- return '';
- if(a == 'W' || a == 'X' || a == 'Y')
- return '';
- }
POJ 1002 487-3279(map映照容器的使用)的更多相关文章
- C++ map 映照容器
map映照容器的元素数据是一个键值和一个映照数据组成的,键值与映照数据之间具有一一映照的关系. map映照容器的数据结构是采用红黑树来实现的,插入键值的元素不允许重复,比较函数只对元素的键值进行比较, ...
- map映照容器的使用
map映照容器可以实现各种不同类型数据的对应关系,有着类似学号表的功能. 今天在做并查集的训练时,就用上了map映照容器. 题目就不上了,直接讲一下用法.顺便说一下,实现过程是在C++的条件下. #i ...
- map映照容器
//map映照容器是由一个键值和一个映照数据组成的,键值与映照数据之间具有一一映照的关系 //map映照容器的键值不允许重复 ,比较函数值对元素 //的键值进行比较,元素的各项数据可通过键值检索出来 ...
- 统计频率(map映照容器的使用)
问题描述 AOA非常喜欢阅读莎士比亚的诗,莎士比亚的诗中有种无形的魅力吸引着他!他认为莎士比亚的诗中之所以些的如此传神,应该是他的构词非常好!所以AOA想知道,在莎士比亚的书中,每个单词出现的频率各 ...
- zoj 2104 Let the Balloon Rise(map映照容器的应用)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2104 题目描述: Contest time again! Ho ...
- zoj 1109 Language of FatMouse(map映照容器的典型应用)
题目连接: acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1109 题目描述: We all know that FatMouse doe ...
- map映照容器(常用的使用方法总结)
map映照容器的数据元素是由一个键值和一个映照数据组成的,键值和映照数据之间具有一一对应的关系.map与set集合容器一样,不允许插入的元素的键值重复. /*关于C++STL中map映照容器的学习,看 ...
- C++STL之map映照容器
map映照容器 map映照容器的元素数据是由一个键值和一个映照数据组成的, 键值与映照数据之间具有一一映照关系. map映照容器的数据结构也是采用红黑树来实现的, 插入元素的键值不允许重复, 比较函数 ...
- POJ 1002 487-3279 (map )
title: 487-3279 map POJ1002 tags: [map] 题目链接 Description Businesses like to have memorable telephone ...
随机推荐
- Linux vi 文本代码时显示行号或不显示行号
Linux vi 文本代码时显示行号或不显示行号 前提 安装了vim $vi ~/.vimrc 显示的话加上 set nu 不想显示的话可以注释掉 "set nu 之后 $source ~ ...
- Hive ORC + SNAPPY
Hive orc 格式 + snappy 压缩是比较常用的存储加压缩格式. 今天处理下面的场景时,解决了一些问题,记录下来: flume消费kafka的数据实时写入hdfs,通过创建分区表,t + 1 ...
- Java-动态代理技术
1.程序中的代理 为具有相同接口的目标类的各个方法,添加一些系统功能,如日志,异常处理,计算方法运行的 时间,事务管理等等,都可以交给另一个类去实现这些功能,该类称为代理类. 注意:为了让代理类共享目 ...
- unigui web app之菜单
unigui web app之菜单 拖放TUnimMenu控件到窗体上. side:=msleft 表示将在左边显示菜单. 菜单项属性 UnimMenu1.Visible := True;显示菜单 U ...
- delphi控制 word的几种方法--转
对几种方法的难易程度的判别 a.通过Delphi的控件TOleContainer 将Word嵌入 这是最简单的Ole嵌入,能够直接将Word文档调用,只需要使用ToleContainer.Run就可以 ...
- STF环境搭建(ubuntu)
一,环境搭建 1. linux 一些基础的工具要有: sudo apt-get update sudo apt-get install git sudo apt-get install lib32st ...
- 迁移桌面程序到MS Store(3)——开机自启动
迁移桌面程序的时候,有可能你会遇到这么个需求——开机自启动.Windows传统桌面程序的传统陋习.不论什么奇葩软件都想要开机自启动,默认就给你打开,一开机哐哐哐什么雷,什么企鹅都蹦出来,也不管你用不用 ...
- abstract抽象
abstract:抽象 是用来修饰抽象类和抽象方法的 那么什么抽象,抽象有究竟有什么用呢?? 我们知道,“类”是某一类具有相同特征或行为的物事,是将这些物事特征向上抽取得来的:“父类”也是子类不断向上 ...
- C#6.0语言规范(十四) 枚举
一个枚举类型是一个独特的值类型(值类型)声明一组命名的常量. 这个例子 enum Color { Red, Green, Blue } 声明了一个名为枚举类型Color与成员Red,Green和Blu ...
- 爬虫 解码gb1312类型
今天我爬虫的时候竟然遇见了网页编码为gb1312类型的网站 , 不是平常的utf-8 遇到这种类型的时候忽视它是最好的办法 ① respond.content.decode('gb18030','i ...