首页 > 其他分享 >北大ACM poj1002 487-3279

北大ACM poj1002 487-3279

时间:2023-08-21 17:06:16浏览次数:42  
标签:10 form map poj1002 310 number ACM telephone 487


487-3279


Time Limit: 2000MS

 

Memory Limit: 65536K

Total Submissions: 191845

 

Accepted: 33280


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


 

 

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char m[]="22233344455566677778889999";
char p[100000][9],buf[1000];
int i,j,k,n,count,duplicate;
main()
{
    scanf("%d\n",&n);
     for(i=0;i<n;i++)
    {gets(buf);
        //忽略连字符 
        for(k=j=0;buf[j];j++)
        {
            if(buf[j]=='-')
                continue;//忽略连字符
            if(buf[j]>='A'&&buf[j]<='Z')
            {
                p[i][k]=m[buf[j]-'A'];
            }
            else if(buf[j]>='0' && buf[j]<='9')
            {
                p[i][k]=buf[j];
            }
            if(++k==3)
                p[i][k++]='-';//在第三位插入连字符
        }
    }
    qsort(p,n,9,strcmp);
    duplicate=0;//0=没有重复,1=有重复的
    count=0;
    for(i=0;++i<=n;)
    {
        count++;//重复次数
        if(strcmp(p[i-1],p[i]))
        {
            if(count>1)//因为已经排好了序,所以只要遇到不同的就说明重复结束 
            {
                printf("%s %d\n",p[i-1],count); 
                duplicate=1;//只要输出了1次就设置成0以外的值 
            }
            count=0;//重设出现次数 
        }
    }
    if(duplicate==0)
        puts("No duplicates.");
}

 

标签:10,form,map,poj1002,310,number,ACM,telephone,487
From: https://blog.51cto.com/u_10101161/7177245

相关文章

  • 北大ACM poj1661 Help Jimmy
    HelpJimmyTimeLimit:1000MS MemoryLimit:10000KTotalSubmissions:7380 Accepted:2333Description"HelpJimmy"是在下图所示的场景上完成的游戏。场景中包括多个长度和高度各不相同的平台。地面是最低的平台,高度为零,长度无限。Jimmy老鼠在时刻0从高......
  • 北大ACM poj1050 To the Max(C++)
    TotheMaxTimeLimit:1000MS MemoryLimit:10000KTotalSubmissions:32446 Accepted:16930DescriptionGivenatwo-dimensionalarrayofpositiveandnegativeintegers,asub-rectangleisanycontiguoussub-arrayofsize1*1orgreaterlocatedwithi......
  • 北大ACM poj2141 Message Decowding
    MessageDecowdingTimeLimit:1000MS MemoryLimit:65536KTotalSubmissions:10326 Accepted:5672DescriptionThecowsarethrilledbecausethey'vejustlearnedaboutencryptingmessages.Theythinktheywillbeabletousesecretmessagestoplot......
  • 北大ACM poj2590
    /*找规律后发现增量是1,1,2,2,3,3,4,4,5,5......,可以发现它是个隔位曾1的自然序列步数:12345678910+1+1+2+2+3+3+4+4+5+501246912......
  • 北大ACM poj1636
    /*problem:poj1636如果s中的每个字母在t中都有则输出Yes(注意是Yes,不是YES)代码很简单,就不解释了*/#include<stdio.h>chars[100010],t[100010];intmain(){while(~scanf("%s%s",s,t)){inti=0,j;for(j=0......
  • ACM题目 英雄护美(递归)
    /*英雄护美英雄救美,可以理解;英雄护美,亦可理解。m(1<=m<=54)个英雄和美晚上行军,路过大峡谷,只能以纵队的方式前行。为确保美的绝对安全,纵队中每两个美之间必须至少有一个以上的英雄。如m为3时,有5种行军方式,分别为:美-英雄-美、美-英雄-英雄、英雄......
  • ACM题目:孔融分梨
    /*孔融分梨孔融让梨,人人称颂;孔融分梨,也不简单。孔融有M个同样的梨,要分给N个人。每个人手上有一个同样的盘子,孔融要将梨放入盘中,允许有的盘子空着不放,问共有多少种不同的分法?3,1,1和1,3,1和1,1,3是同一种分法。第一行是测试数据的数目t(0<......
  • ACM题目:英雄护美
    /*英雄护美英雄救美,可以理解;英雄护美,亦可理解。m(1<=m<=54)个英雄和美晚上行军,路过大峡谷,只能以纵队的方式前行。为确保美的绝对安全,纵队中每两个美之间必须至少有一个以上的英雄。如m为3时,有5种行军方式,分别为:美-英雄-美、美-英雄-英雄、英......
  • 北大ACM poj1562
    /*problem:poj1562*author:gubojun*time:2012.7.27*language:C*题目大意:求有多少个不相连的区域代码中的解释很多了,别的不说了*/#include<stdio.h>#include<string.h>#defineN101charmap[N][N];intn,m,sum;voiddfs(inti,intj){//如果map[......
  • 北大ACM poj 1001
    网上搜来的借鉴一下#include<stdio.h>main(){doublef;intn,i,j;inttop,bottom;intshow;for(;~scanf("%lf%d",&f,&n);){intp[300]={1},tmp=0;f*=1e6;for(i=0;i++<n;)......