UVA 755 && POJ 1002 (13.08.05)
来源:互联网 发布:压力测试软件 web 编辑:程序博客网 时间:2024/05/18 03:20
487-3279
Businesses like to have memorable telephone numbers. One way to make a telephone number memorableis to have it spell a memorable word or phrase. For example, you can call the University of Waterloo bydialing the memorable TUT-GLOP. Sometimes only part of the number is used to spell a word. Whenyou get back to your hotel tonight you can order a pizza from Gino's by dialing 310-GINO. Anotherway to make a telephone number memorable is to group the digits in a memorable way. You couldorder your pizza from Pizza Hut by calling their ``three tens'' number 3-10-10-10.
The standard form of a telephone number is seven decimal digits with a hyphen between the third andfourth 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 thestandard 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 thequality control process you want to check that no two (or more) businesses in the directory have the same telephone number.
Input
The first line of the input contains the number of datasets in the input. A blank line follows. The first line of each dataset specifies the number of telephone numbersin the directory (up to 100,000) as a positive integer alone on the line. The remaining lines list thetelephone numbers in the directory, with each number alone on a line. Each telephone number consistsof a string composed of decimal digits, uppercase letters (excluding Q and Z) and hyphens. Exactlyseven of the characters in the string will be digits or letters. There's a blank line between datasets.Output
Generate a line of output for each telephone number that appears more than once in any form. Theline should give the telephone number in standard form, followed by a space, followed by the numberof times the telephone number appears in the directory. Arrange the output lines by telephone numberin ascending lexicographical order. If there are no duplicates in the input print the line:No duplicates.
Print a blank line between datasets.
Sample Input
1124873279ITS-EASY888-45673-10-10-10888-GLOPTUT-GLOP967-11-11310-GINOF101010888-1200-4-8-7-3-2-7-9-487-3279
Sample Output
310-1010 2487-3279 4888-4567 3
题意:
根据翻译规则, 把给出的另类电话号码翻译成标准形式
输出的是有重复的电话号码, 号码后面跟着的数字就是重复几次;
做法: (几个要点)
其一, 设定一个转化模板 (方便)
其二. 把电话号码按int值存起来 (直接)
另外要提到: 在UVA上提交此题会一直提交错误, 似乎在UVA上不能提交, 然后POJ上也有, 但是POJ上的题目题意只要求一组数据即可, 比较水
代码(按多组数据写的, 不能在POJ上提交, 要稍微修改)
#include<stdio.h>#include<ctype.h>#include<string.h>#include<stdlib.h>int cmp(const void *a, const void *b) {return (*(int *)a - *(int *)b);}int change[] = {2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};int number[100005];int main() {int T;scanf("%d", &T);while(T--) {//每一组测试要用的量:int num_phone;int pos = 0;int i, j, sum;char str[1005];scanf("%d", &num_phone);getchar();//开始读取并处理:while(num_phone--) {gets(str);int len = strlen(str);sum = 0;for(i = 0; i < len; i++) {if(isupper(str[i]))sum = sum * 10 + (change[str[i] - 'A']);else if(isdigit(str[i]))sum = sum * 10 + str[i] - '0';}number[pos++] = sum;}//读取完排序,排完序可利用桶排序的思路:qsort(number, pos, sizeof(number[0]), cmp);//统计是否有重复的数:int re = 0;for(i = 0; i < pos; ) {int count = 1;for(j = i+1; j < pos; j++) {if(number[i] == number[j])count++;elsebreak;}if(count > 1) {re = 1;printf("%03d-%04d %d\n", number[i]/10000, number[i]%10000, count);}i = j;}if(re == 0)printf("No duplicates.\n");if(T)printf("\n");}return 0;}
- UVA 755 && POJ 1002 (13.08.05)
- UVa 755 / POJ 1002 - 487-3279
- UVa 755 - 487--3279 Or Poj 1002
- uva 755 poj 1002 487-3279
- uva 755/poj 1002 487-3279
- POJ 1002 UVA 755 487--3279 电话排序 简单但不容易的水题
- UVa 755 / POJ 1002 / East Central North America 1999 487--3279 (排序)
- uva 1394&poj 3517
- POJ 2662 UVA 10917
- poj 1852 && uva 10881
- uva 657 poj 1481
- poj 2251 uva 532
- uva 409 poj 1598
- poj 2325 && uva 10527
- poj 2249 && uva 530
- POJ 3368 & UVA 11235
- POJ 1003 & UVA 2294
- POJ 1338 & UVA 136
- HDU 4604 Deque
- ActiveMQ高级特性:虚拟Destinations实现消费者分组与简单路由
- COCOS2D-X 关于 fatal error C1083: 无法打开包括文件:“CCStdC.h” 的问题
- 130805codeforces练习赛
- iOS: NSString的方法cStringUsingEncoding:
- UVA 755 && POJ 1002 (13.08.05)
- tmux使用简介——如何解决使用linux远程终端的掉线问题(保存远程服务器工作现场)
- 面试题28:字符串的排列
- CodeForces 122A Lucky Division
- DTCoreText下载
- 【转】理解应用层协议 纯C语言实现ftp上传下载
- iOS: NSString的方法dataUsingEncoding:
- uva 10123
- log4net 配置文件配置方法