ACM题目:487-3279
题目是这样子的
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
Output
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 下面先给出解决思路
1. vector<string>类型的数据结构存储输入的原始号码
2. 函数vector<int> ConvertToNeatNumbers(const vector<string>)处理得到的字符串,得到纯净的数字号码
3. 比较区别
4. 输出结果 -------------------------------- 看了网上人家的解决方法完全汗颜了,上代码先
#include <cstdio>
#include <algorithm>
using namespace std;
char s[]; int Hash()
{
int sum = ;
for(int i=,k=;k<;i++)
{
if(s[i]>='' && s[i]<='')
{
sum *=;
k++;
sum+=(s[i]-'');
}
else if(s[i] >= 'A' && s[i]<'Z')
{
sum *=;
k++;
sum+=((s[i]-'A'-(s[i]>'Q'))/+);
}
}
return sum;
} int main()
{
int n;
scanf("%d",&n); int data[n];
getchar(); for(int tmp=;tmp<n;tmp++)
{
gets(s);
data[tmp] = Hash();
}
sort(data, data+n);
bool p = false;
n--;
for(int i=,num=; i<n; i+=num=)
{
while(data[i] == data[i+])
{
num++;
i++;
}
if(num>)
{
printf("%03d-%04d %d\n",data[i]/, data[i]%,num);
p = true;
}
}
if(!p)
printf("No duplicates.\n");
return ;
}
人家用一个哈希就完美解决了这个问题,果断学习一下。
如果大家有什么好的方法欢迎留言讨论奥
ACM题目:487-3279的更多相关文章
- ACM题目————中缀表达式转后缀
题目描述 我们熟悉的表达式如a+b.a+b*(c+d)等都属于中缀表达式.中缀表达式就是(对于双目运算符来说)操作符在两个操作数中间:num1 operand num2.同理,后缀表达式就是操作符在两 ...
- HDU ACM 题目分类
模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...
- ACM题目推荐(刘汝佳书上出现的一些题目)[非原创]
原地址:http://blog.csdn.net/hncqp/article/details/1758337 推荐一些题目,希望对参与ICPC竞赛的同学有所帮助. POJ上一些题目在http://16 ...
- 有一种acm题目叫做,奇葩!
本文全然没有技术含量,纯粹是娱乐. 我事实上想写点东西.可是近期好像做计算几何做得太多了,一种想说说不出东西的感觉,唯有写一下一些奇葩的题目了. HDU3337:Guess the number pi ...
- ACM题目————STL练习之求次数
题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=1112 描述 题意很简单,给一个数n 以及一个字符串str,区间[i,i+n-1] 为一个 ...
- ACM题目————zoj问题
题目1006:ZOJ问题 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:20322 解决:3560 题目描述: 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC. ...
- ACM题目————又见拦截导弹
描述 大家对拦截导弹那个题目应该比较熟悉了,我再叙述一下题意:某国为了防御敌国的导弹袭击,新研制出来一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:它的第一发炮弹能够到达任意的高度,但是以后每一发炮 ...
- ACM题目————还是畅通工程
Submit Status Description 某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离.省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路 ...
- ACM题目————小A的计算器
Description 以往的操作系统内部的数据表示都是二进制方式,小A新写了一个操作系统,系统内部的数据表示为26进制,其中0-25分别由a-z表示. 现在小A要在这个操作系统上实现一个计算器,这 ...
- ACM题目————二叉树的遍历
一.二叉树的后序遍历: 题目描述 给定一颗二叉树,要求输出二叉树的深度以及后序遍历二叉树得到的序列.本题假设二叉树的结点数不超过1000 输入 输 入数据分为多组,第一行是测试数据的组数n,下面的n行 ...
随机推荐
- ACM/ICPC2014鞍山现场赛E hdu5074Hatsune Miku
题目链接:pid=5074">http://acm.hdu.edu.cn/showproblem.php?pid=5074 题意: 给定一个m*m的矩阵mp.然后给定一个长度为n的序列 ...
- 20141112 WinForm子窗口标签页
(一)标签页 先看看效果: 代码: public partial class 标签页 : Form { string s = ""; public 标签页() { Initiali ...
- Memcached管理
安装memcached服务端: apt-get install memcached 配置文件存在于: /etc/memcached.conf 启动memcache: memcached -d -m - ...
- nginx 几个参数
worker_processes : When set to 'auto', which is also the default behavior, Tengine will create the s ...
- JavaWeb核心编程之(三.5)HTTP请求和接受表单数据
HTTP简介WEB浏览器与WEB拂去其之间的一问一答的交互过程, 必须遵循一定的规则,这个规则就是HTTP协议HTTP是hypertext transfer protocol(超文本传输协议)的简写, ...
- Atom power-mode
最近看到很多大牛都在用这个酷炫狂拽掉渣天的插件,于是就默默地git了一波.实际结果就是机械键盘加上砰砰砰砰,根本停不下来有没有. 建议(ˉ(∞)ˉ) :视力2.0的同学不建议使用,眼瞎的同学用就用吧, ...
- Cross-site scripting
Cross-site scripting (XSS) is a type of computer security vulnerability typically found in Web appli ...
- OSG显示文字——自定义显示文字函数
#include <Windows.h> #include <osg/Geode> #include <osg/Geometry> #include <osg ...
- C语言-字符编码转换:UTF与GB2312
依赖库libiconv,libiconv库的交叉编译不做描述,网上很多 #include <stdio.h> #include <stdlib.h> #include < ...
- 【Win7激活工具2013版下载】适用于旗舰版、家庭高级版等所有版本32/64位 OEM激活
虽然现在Win8已经发布了,但是身边总是还有一些朋友在用着Win7系统,而近期微软频繁的推送补丁包,导致之前的那些激活都失效了.找了网络上很多工具,之前的那些有的已经不能用了,激活不了,今天就推荐一些 ...