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 ...
随机推荐
- cpld fpga 区别
cpld fpga 区别 系统的比较,与大家共享: 尽管FPGA和CPLD都是可编程ASIC器件,有很多共同特点,但由于CPLD和FPGA结构上的差异,具有各自的特点: ①CPLD更适合完成各种算法和 ...
- ASP.NET Web API 框架研究 Controller创建 HttpController 类型解析 选择 创建
上一篇介绍了HttpController的一些细节,接下来说下HttpController 类型解析.选择和创建.生产HttpController实例的生产线如下图: 一.涉及的类及源码分析 涉及的类 ...
- 把EXE可执行文件等作为资源包含在Delphi编译文件中
摘自我自己过去写的一段心得. 1.编辑资源文件 *.RCWave: 资源文件是声音文件:RCDATA: 二进制数据AVI: AVI动画:ICON: 图标文件:BITMAP: 位图文件:CURSOR: ...
- Network in Network 2
<Network in Network>论文笔记 1.综述 这篇文章有两个很重要的观点: 1×1卷积的使用 文中提出使用mlpconv网络层替代传统的convolution层.mlp层实际 ...
- C# 在WPF中使用Exceptionless异常日志框架
登录http://exceptionless.com/官网,注册一个账户. 创建项目 选择wpf项目类型 拷贝下箭头指的这个密钥,过后程序里用的到. 下面我们打开vs,新建一个wpf的项目 打开git ...
- Python 库,资源
库名称简介 Chardet字符编码探测器,可以自动检测文本.网页.xml的编码. colorama主要用来给文本添加各种颜色,并且非常简单易用. Prettytable主要用于在终端或浏览器端构建格式 ...
- js 正则语法
原文:一次性搞懂javascript正则表达式之语法 看完原文,对正则中以前一知半解的捕获组与非捕获组.零宽断言有了更深的理解.很感谢原文作者~~ 普通字符 当我们写a的时候,我们指的就是a:当我们写 ...
- Smart/400开发上手5: Cobol开发标准
ENVIRONMENT DIVISION. CONFIGURATION SECTION.SOURCE-COMPUTER. IBM-AS400.OBJECT-COMPUTER. IBM-AS400. 这 ...
- Pycharm配置autopep8:自动调整代码为PEP8风格
关于PEP 8 PEP 8,Style Guide for Python Code,是Python官方推出编码约定,主要是为了保证 Python 编码的风格一致,提高代码的可读性. 官网地址:http ...
- [Umbraco] 项目结构
主要包括以下几个部分 Umbraco.businesslogic(基础) Umbraco.cms (核心) Umbraco.controls(控件) Umbraco.datalayer(数据) Umb ...