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 ...
随机推荐
- yum-阿里源配置
原文:https://opsx.alibaba.com/mirrorCentOS 1.备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/ ...
- 使用dbms_profiler包测试存储过程性能
原文地址 http://hi.baidu.com/edeed/blog/item/345401e9a8851d38b80e2db4.html dbms_profiler用来测试PL/SQL代码非常 ...
- 数据库索引、B树、B+树
数据库索引,是数据库管理系统中一个排序的数据结构,以协助快速查询.更新数据库表中数据.索引的实现通常使用B树及其变种B+树. 在数据之外,数据库系统还维护着满足特定查找算法的数据结构,这些数据结构以某 ...
- 简谈Entity Framework的优缺点
Entity Framework简介 Entity Framework的全称为 ADO.NET Entity Framework ,简称为EF, 是微软以ADO.NET为基础发展出来的实体框架,早期被 ...
- C# json字符串转为对象
方法1: using System.Web.Script.Serialization; string ss = "{\"NewsCount\":\"3482\& ...
- AJPFX外汇的常见形态
AJPFX:外汇价常见形态 外汇的价格,本质上是由供求关系决定的,但是在技术分析的世界里,是什么原因导致供求关系的改变并不重要,也没有人能准确的找出所有的因素并加以判断,但是供求关系被改变后的外汇走势 ...
- kls与flag(map)
题目传送门 这道题还挺搞笑的,\(map\)常数贼大还是把它水过了. 可以发现这道题求的是 \((j>i)j-i=h_i+h_j,j-i=|h_i-h_j|\)的对数. 那么显然,因为高度大于\ ...
- 07_python_集合深浅拷贝
一.join li = ["李嘉诚", "麻花藤", "林海峰", "刘嘉玲"] s = "_".j ...
- jsp的两个include了解
在jsp中三大指令(page -- include -- taglib)中有一个 include 然后再三个动作标签中(include -- forward -- param)中也有一个includ ...
- Django(ORM查询1)
day69 参考:http://www.cnblogs.com/liwenzhou/p/8660826.html 在Python脚本中调用Django环境 orm1.py import os if _ ...