poj 1002 stl map

487-3279
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 198847 Accepted: 34639

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




题意:

将输入的号码进行转化,使其变成***-****的形式,其中A~Z的字符可以按上给出的规则转化为数字(除Q与Z外),输出转换后号码的重复数大于1的号码以及其重复的次数。


思路:

其实就是一道简单模拟题。但是我是用STL中的map做的,虽然时间长了些,但是简单嘛,而且主要目的在练map。
不得不说,这道题首先做复杂了,还是因为map用的不熟。。。
只要一个map<string,int> a;
然后每次对一个号码转化后,就直接将其对应的int型的量加一即可。 eg a[" "]++;
ps. 对于一开始map中每个string的对应的int值都为0.
即:cout<<a["string"];
输出值为0。
且map中key值(即此处的string)唯一

eg. a["string"]++
把“string”对应的int值改变成原来对应的加一。

针对题目,还有要注意的是:如果没有重复以上的号码,输出“No duplicates.”




代码:
View Code
 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<map>
 4 #include<string.h>
 5 #include<string>
 6 using namespace std;
 7 //int times[100005];
 8 int main(){
 9     map <char,char> num;
10     char i1='2';
11     for(int i=1;i<=26;i1++){
12             for(int j=1;j<=3;i++){
13                     if(('Q'-'A'==i-1)||('Z'-'A'==i-1))
14                          continue;
15                     char temp=i+'A'-1;
16                     num[temp]=i1;
17                     j++;
18                     }
19                     }
20    // cout<<num['C']<<" "<<num['F']<<" "<<num['W']<<" "<<num['Y']<<" "<<num['A']<<endl;
21     int n;
22     while(cin>>n){
23      //  memset(times,0,sizeof(times));
24        map <string,int> mapp;
25        getchar();
26        for(int i=1;i<=n;i++){
27                char temp1[305];
28                gets(temp1);
29              //  cin>>temp1;
30                char temp2[305];
31                int lena=strlen(temp1);
32                int lenb=0;
33                for(int j=0;j<lena;j++){
34                        if(temp1[j]!='-'){
35                               if(temp1[j]<'Z'&&temp1[j]>='A'&&temp1[j]!='Q'&&temp1[j]!='Z'){
36                                      temp2[lenb]=num[temp1[j]];
37                                      }
38                               else{
39                                      temp2[lenb]=temp1[j];
40                                      }
41                               lenb++;
42                                      }
43                               }
44                if(lenb!=7)
45                     continue;
46                string temp3=temp2;
47                mapp[temp3]++;
48                     }
49        int sum=0;
50        for(map<string,int>::iterator it=mapp.begin();it!=mapp.end();it++){
51                                      if((it->second)>1){
52                                          sum++;
53                                          string temp5=it->first;
54                                          for(int k=0;k<7;k++){
55                                                  cout<<temp5[k];
56                                                  if(k==2)
57                                                      cout<<'-';
58                                                      }
59                                          cout<<" "<<it->second<<endl;
60                                          }
61                                      }
62        if(sum==0)
63           cout<<"No duplicates."<<endl;
64                                      }
65        return 0;
66        }
67                

 




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值