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 ...
随机推荐
- centos部署yapi爬坑记
前言 这几天终于完成了为期三个月的公司某个demo版的项目,在这期间和公司的后台因为API的事怼过无数次了,'我的接口没问题,是你请求的方式不对吧!'.'一定是你请求的参数不对'......诸如此类问 ...
- 阿里云oss服务通用类
在webconfig中配置信息 <?xml version="1.0" encoding="utf-8"?><configuration> ...
- SAS Shortcut Keys
最常用的键有F3(运行代码).F6(查看log信息).Ctrl + / (注释代码).Ctrl + Shift + / (取消代码注释) SAS系统一共有4类快捷键,其中部分有重复, 第一类可自定义. ...
- execution表达式--小坑
之前使用的都是eclipse,今天开始复习spring了,开始接触IDEA,在复习过程中,出了点小事, 复习到AOP开发时,有半自动和全自动之说,之前我看那期视频里面没讲过全自动,我就自己再那敲Dem ...
- JavaScript 那些不经意间发生的数据类型自动转换
JavaScript可以自由的进行数据类型转换,也提供了多种显式转换的方式.但是更多的情况下,是由JavaScript自动转换的,当然这些转换遵循着一定的规则,了解数据类型自由转换的规则是非常必要的. ...
- Django两天搭建个人博客
传送门:https://github.com/1417766861/django-blog(可直接运行,上面有步骤) 效果: 首页: 侧栏: 详情页面: 修改头像,资料,文章发布: 支持添加标签拖拽 ...
- socket http tcp udp ip 协议
Socket可以支持不同的传输层协议(TCP或UDP),当使用TCP协议进行连接时,该Socket连接就是一个TCP连接. socket是在应用层和传输层之间的一个抽象层,它把TCP/IP层复杂的操作 ...
- Oracle 11g安装时针对不同操作系统所需的依赖包查询地址
http://docs.oracle.com/cd/E11882_01/install.112/e24326/ 点击连接,出现页面,往下滑动:)
- python使用(四)
1.file_os_option.py2.file_option.py3.configfile_option.py4.logger_option.py 1.file_os_option.py # co ...
- MySQL笔记(3)---文件
1.前言 第二章简单记录了一下InnoDB存储引擎的一个基本内容,介绍了保证高效插入的Insert Buffer,change Buffer和确保数据安全的write ahead log以及doubl ...