poj1002(水题)

1.题目描述

487-3279

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 244177   Accepted: 43308

Description

Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or phrase. For example, you can call the University of Waterloo by dialing the memorable TUT-GLOP. Sometimes only part of the number is used to spell a word. When you get back to your hotel tonight you can order a pizza from Gino‘s by dialing 310-GINO. Another way to make a telephone number memorable is to group the digits in a memorable way. You could order 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 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

The 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

Generate 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.题目大意

  输入n行字符,把每行改成相应的电话号码,输入为大写字母(除了“Q”和“Z”外)、数字有效,其他无效,然后输出重复的电话号码和重复的次数(>=2);

  输出格式为xxx-xxxx x(次数)

3.解决方法

  多种数据结构可以做,我这里用最简单的数组,一个记录出现次数,一个记录次数大于2的号码,然后输出。

4.代码

 1 #include <iostream>
 2 #include <cmath>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <algorithm>
 6 using namespace std;
 7
 8 int judge(char c)
 9 {
10     if (((c>=‘0‘)&&(c<=‘9‘))||((c>=‘A‘)&&(c<‘Z‘)&&c!=‘Q‘))
11         return 1;
12      return 0;
13 }
14 int a[10000000],b[10000000];
15 int make (char c)
16 {
17     if ((c>=‘0‘)&&(c<=‘9‘)){
18         return (int)(c-‘0‘);
19     }
20     if ((c>=‘A‘)&&(c<=‘O‘)){
21         return ((int)(c-‘A‘)/3+2);
22     }
23     if (c<=‘S‘)return 7;
24     if (c<=‘V‘)return 8;
25     if (c<=‘Y‘)return 9;
26 }
27 int main()
28 {
29     int n,i,d,t,k=0,sum,len;
30     char s[10000];
31     scanf("%d",&n);
32     memset(a,0,sizeof(a));
33     for (i=1;i<=n;i++){
34         scanf("%s",&s);
35         d=0;
36         t=0;
37         len=strlen(s);
38         sum=0;
39         while (t<=7&&d<len){
40             if (judge(s[d])){
41                 t++;
42                 sum=sum*10+make(s[d]);
43             }
44             d++;
45         }
46         a[sum]++;
47         if (a[sum]==2){
48             b[k]=sum;
49             k++;
50         }
51     }
52     sort(b,b+k);
53     if (k==0)printf("No duplicates.\n");
54     for (i=0;i<k;i++){
55         printf("%03d-%04d %d\n",b[i]/10000,b[i]%10000,a[b[i]]);
56     }
57     return 0;
58 }
时间: 2024-08-09 06:35:32

poj1002(水题)的相关文章

【转载】POJ水题大集合

POJ水题大集合 poj1000:A+B problempoj1002:电话上按键对应着数字.现在给n个电话,求排序.相同的归一类poj1003:求最小的n让1+1/2+1/3+...+1/n大于给的一个实数poj1004:求一堆实数的平均数poj1005:由坐标 (0,0) 开始,以半圆为形状每年侵蚀50m^2,问(0,0)开始到(x,y)结束需要多长时间poj1006:三个周期是常数.现在给三个周期出现高峰的时候,问下一次出现高峰是什么时候poj1007:求字符串排序poj1008:一种日历

2015南阳CCPC L - Huatuo&#39;s Medicine 水题

L - Huatuo's Medicine Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Huatuo was a famous doctor. He use identical bottles to carry the medicine. There are different types of medicine. Huatuo put medicines into the bottles and chain these b

sdut 2841 Bit Problem (水题)

题目 贴这个题是因为看题解有更简单的方法, 我做的时候是直接算的, 也很简单. 贴一下题解吧: 如果一个整数不等于 0,那么该整数的二进制表示中至少有一位是 1. 这个题结果可以直接输出 x - (x&(x-1)); 因为x-1 之后二进制下,就是最右边的1变成了0, 最右边的1的 右边所有的0变成了1, 不影响最左边. 我的代码: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4

sdut 2413:n a^o7 !(第三届山东省省赛原题,水题,字符串处理)

n a^o7 ! Time Limit: 1000MS Memory limit: 65536K 题目描述 All brave and intelligent fighters, next you will step into a distinctive battleground which is full of sweet and happiness. If you want to win the battle, you must do warm-up according to my inst

杭电(hdu)2053 Switch Game 水题

Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 13113    Accepted Submission(s): 7970 Problem Description There are many lamps in a line. All of them are off at first. A series of o

4.7-4.9补题+水题+高维前缀和

题目链接:51nod 1718 Cos的多项式  [数学] 题解: 2cosx=2cosx 2cos2x=(2cosx)^2-2 2cos3x=(2cosx)^3-3*(2cosx) 数归证明2cos(nx)能表示成关于2cosx的多项式,设为f(n) f(1)=x,f(2)=x^2-2(其中的x就是2cosx) 假设n=1~k时均成立(k>=3) 当n=k+1时 由cos((k+1)x)=cos(kx)cos(x)-sin(kx)sin(x) cos((k-1)x)=cos(kx)cos(x)

历年NOIP水题泛做

快noip了就乱做一下历年的noip题目咯.. noip2014 飞扬的小鸟 其实这道题并不是很难,但是就有点难搞 听说男神错了一个小时.. 就是$f_{i,j}$表示在第$i$个位置高度为$j$的时候最小点击次数 递推的话对于上升的情况只做一次,后面几次在后面再做.. #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using namespace st

[ZPG TEST 114] 阿狸的英文名【水题】

1.      阿狸的英文名 阿狸最近想起一个英文名,于是他在网上查了很多个名字.他发现一些名字可以由两个不同的名字各取一部分得来,例如John(约翰)的前缀 "John"和Robinson(鲁滨逊)的后缀 "son" 连在一起就是Johnson. 现在他找到了两个喜欢的名字(名字可看作字符串),用A和B表示,他想知道取A的一个非空前缀和B的一个非空后缀,连接在一起能组成多少不同的字符串. 输入格式 输入两行,分别表示字符串A和B:字符串只包含小写英文字母. 输出格

G - Brain Network (easy)(并查集水题)

G - Brain Network (easy) Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u CodeForces 690C1 Description One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know