poj 1002 487-3279

http://poj.org/problem?id=1002

487-3279

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的电话号按照号码词典的顺序输出

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <limits>
#include <queue>
#include <stack>
#include <vector>
#include <map>

using namespace std;

#define N 100500
#define INF 0x3f3f3f3f
#define PI acos (-1.0)
#define EPS 1e-8
#define met(a, b) memset (a, b, sizeof (a))

typedef long long LL;

struct node
{
    char str[50];
    int num;
} p1[N], p2[N];

bool cmp (node a, node b)
{
    return (strcmp (a.str, b.str) < 0);
}

int Num (char ch)//找出每个字符所对应的值
{
    if (ch == 'A' || ch == 'B' || ch == 'C') return 2;
    else if (ch == 'D' || ch == 'E' || ch == 'F') return 3;
    else if (ch == 'G' || ch == 'H' || ch == 'I') return 4;
    else if (ch == 'J' || ch == 'K' || ch == 'L') return 5;
    else if (ch == 'M' || ch == 'N' || ch == 'O') return 6;
    else if (ch == 'P' || ch == 'R' || ch == 'S') return 7;
    else if (ch == 'T' || ch == 'U' || ch == 'V') return 8;
    else if (ch == 'W' || ch == 'X' || ch == 'Y') return 9;
    else if (ch >= '0' && ch <= '9') return ch-'0';
}

int main ()
{
    int n, flag = 0;
    scanf ("%d", &n);

    for (int i=0; i<n; i++)
    {
        scanf ("%s", p1[i].str);
        p2[i].num = 1;
    }

    for (int i=0; i<n; i++)
    {
        int k = 0;
        for (int j=0; p1[i].str[j]; j++)
        {
            if (p1[i].str[j] != '-')
                p2[i].str[k++] = Num (p1[i].str[j]) + '0';
        }
        p2[i].str[k] = '\0';
    }

    sort (p2, p2+n, cmp);
    int Index = 0;

    for (int i=0; i<n; i++)
    {
        if (strcmp (p2[i].str, p2[i+1].str) && i+1-Index>=2)//如果这个电话号出现的次数>=2的时候输出
        {
            printf ("%c%c%c-%c%c%c%c %d\n", p2[i].str[0], p2[i].str[1], p2[i].str[2], p2[i].str[3], p2[i].str[4], p2[i].str[5], p2[i].str[6], i+1-Index);
            Index = i;
        }
        else if (!strcmp (p2[i].str, p2[i+1].str)) flag = 1;

       if (strcmp (p2[i].str, p2[i+1].str) && i-Index<2) Index++;
    }

    if (!flag) puts ("No duplicates. ");//没有重复的就输出"No duplicates. "

    if (Index == -1 && flag) printf ("%c%c%c-%c%c%c%c %d\n", p2[0].str[0], p2[0].str[1], p2[0].str[2], p2[0].str[3], p2[0].str[4], p2[0].str[5], p2[0].str[6], n);
    //只有一个电话号,并且这个电话号出现的次数>=2
    return 0;
}


你可能感兴趣的:(poj 1002 487-3279)