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行 ...
随机推荐
- Highways(求最小生成树的最大边)
Highways Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Total Sub ...
- Afinal开源框架中FinalActivity的使用
1. 首先将afinal.jar文件复制到项目中的libs文件夹下 2. 让MainActivity不在继承系统的Activity,而是继承FinalActivity public class Mai ...
- LeetCode: Surrounded Regions [130]
[题目] Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is cap ...
- 【数据库】SQL优化方法汇总
最近在研究SQL语句的优化问题. 下面是从网上搜集的,有的地方有点老了,可是还是有很多可以借鉴的地方的. 如何加快查询速度? 1.升级硬件. 2.根据查询条件,建立索引,优化索引.优化访问方式,限制结 ...
- jQuery实现拖动布局并将排序结果保存到数据库
很多网站的拖动布局的例子都是采用浏览器的COOKIE来记录用户拖动模块的位置,也就是说拖动后各模块的排序位置信息是记录在客户端的cookie里的.当用户清空客户端的cookie或浏览器的cookie过 ...
- winform CheckedListBox实现全选/全不选
/全选 private void button3_Click(object sender, EventArgs e) { for (int i ...
- log4j异常问题
log4j:WARN No appenders could be found for logger 转自:最爱NBA 直接写我的解决办法:在src下面新建file名为log4j.propertie ...
- 使用VC++通过远程进程注入来实现HOOK指定进程的某个API
前阵子读到一篇关于<HOOK API入门之Hook自己程序的MessageBoxW>的博客,博客地址:http://blog.csdn.net/friendan/article/detai ...
- 图论测试题(一)第一题:longest
第一题:longest 乌托邦有n个城市,某些城市之间有公路连接.任意两个城市都可以通过公路直接或者间接到达,并且任意两个城市之间有且仅有一条路径(What does this imply? A tr ...
- 项目中怎么去掉tomcat的猫
其实很简单,需要在登录页和显示内容的主页,将自己的favicon.ico 导入,并在登录页和主页将其引入即可. 例如: 接着在登录页引入 <link rel="shortcut ic ...