poj 1002 487-3279

487-3279

Time Limit: 2000MS

Memory Limit: 65536K

Total Submissions: 202541

Accepted: 35264

Description

Businesses like to have memorable telephonenumbers. One way to make a telephone number memorable is to have it spell amemorable word or phrase. For example, you can call the University of Waterlooby dialing the memorable TUT-GLOP. Sometimes only part of the number is used tospell a word. When you get back to your hotel tonight you can order a pizzafrom Gino's by dialing 310-GINO. Another way to make a telephone numbermemorable is to group the digits in a memorable way. You could order your pizzafrom Pizza Hut by calling their ``three tens'' number 3-10-10-10. 

The standard form of a telephone number isseven 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, asfollows: 

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 arenot dialed, and can be added and removed as necessary. The standard form ofTUT-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 theyhave the same standard form. (They dial the same number.) 

Your company is compiling a directory oftelephone numbers from local businesses. As part of the quality control processyou want to check that no two (or more) businesses in the directory have thesame telephone number.

Input

The inputwill consist of one case. The first line of the input specifies the number oftelephone numbers in the directory (up to 100,000) as a positive integer aloneon 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 stringcomposed 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 aline of output for each telephone number that appears more than once in anyform. The line should give the telephone number in standard form, followed by aspace, followed by the number of times the telephone number appears in thedirectory. Arrange the output lines by telephone number in ascendinglexicographical 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

Source

East Central North America 1999

 

 

487-3279

Time Limit: 2000MS

Memory Limit: 65536K

Total Submissions: 202541

Accepted: 35264

Description

商业上喜欢使用比较容易记住的电话号码。有一种方法帮助记忆电话号码,就是使用容易拼写的字母和词组来辅助记忆。举个例子,你可以通过拨打电话TUT-GLOP来联系Waterloo大学。有时候,使用单词来代替一部分电话号码。当你今晚回到旅馆,你可以通过拨打310-GINO来订披萨。你也可以用另一种方式来记忆电话号码,就是把数字组合成一个比较容易记忆的方式。通过叫你的披萨店的号码“三个十”3-10-10-10,来记忆号码。
电话号码的标准形式是7个数字每3-4个之间用连字符链接。键区提供的字母与数字的映射如下。
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 

这里没有对Q和Z的映射。连字符不需要拨打,而且在必要条件下可以增加或者删除。TUT-GLOP的标准形式是888-4567,而310-GINO的标准形式是310-4466,3-10-10-10的标准形式是310-1010

两个电话号码如果标准形式相同,则这两个电话号码是相等的

你的公司准备在当地的商界中编辑一个电话簿,为了更有质量的控制,你希望能够检查在电话簿中是否有重复的电话号码。 

 

Input

输入包括一组数据。第一行表示有多少个电话号码(最多100000),其他行陈列出号码。每一串号码,包括数字,大写字母(没有Q和Z)和连字符。

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

Source

East Central North America 1999

 

水题,处理下字符串排个序即可。

做法很水,就是读入,处理,排序,挑重复的输出。效率比较低

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
void Output(int n, char number[][10]);
void init(int n, char number[][10]);
int cmp(const void *a, const void *b);
 
int main()
{
   int n;//10w
   char number[111111][10];
   freopen("in.txt", "r", stdin);
   scanf("%d", &n);
   //printf("%d\n", n);
   init(n, number);
   Output(n, number);
   return 0;
}
 
void init(int n, char number[][10]){
   int i, j, len,map[26]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,0,7,7,8,8,8,9,9,9,0};
   char s[111];
   int k = 0;
   int p;
 
   for (i = 0; i < n;i ++){
       scanf("%s", s);
       //printf("%s", s);
       len = strlen(s);
       p = 0;
       for (j = 0;j < len; j++){
           if (s[j] >= 'A' && s[j] <='Z'){
 
                number[k][p] = map[s[j]-'A'] +'0';
                p++;
                //printf("%c",number[k][p]);
           }
           if (s[j] >= 'a' && s[j] <= 'z'){
                number[k][p] = map[s[j]-'a'] +'0';
                p++;
                //printf("%c",number[k][p]);
           }
           if (s[j] >= '0' && s[j] <= '9'){
                number[k][p] = s[j];
                p++;
                //printf("%c",number[k][p]);
           }
       }
       number[k][p]=0;
       //printf("%s\n", number[k]);
       k++;
    }
   qsort(number, n, sizeof(number[0]), cmp);
    /*for (i = 0;i < n;i ++){
       printf("%s\n", number[i]);
   }*/
}
 
int cmp(const void *a, const void *b){
   return strcmp((char *)a, (char *)b);
}
 
void Output(int n, char number[][10]){
   int i, j, flag = 0,bflag = 0, k = 0;
   /*for (i = 0;i < n;i ++){
       printf("%s\n", number[i]);
   }*/
 
   for (i = 0; i < n; i++){
       if(strcmp(number[i], number[i+1]) == 0){
           flag = 1;
           bflag = 1;
           k++;
       }else if(flag){
           for (j = 0;j < 7;j ++){
                if (j == 3)
                    printf("-");
                printf("%c",number[i][j]);
           }
           flag = 0;
           printf(" %d\n",k+1);
           k=0;
       }
    }
   if (bflag==0){
       printf("No duplicates.");
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值