//电话号码匹配问题

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.

//相同电话号码的判断
#include
#include
#include

using namespace std;

const int maxn = 20 ;
int Hash(string s)
{
    int sum=0;         //存储结果
    for(int i=0;iif(s[i]>='0'&&s[i]<='9')
        {
            sum=sum*10+s[i]-'0';//字符数据转化为整型数据
        }
        else
            if(s[i]>='A'&&s[i]<='Z')
            {
                sum=sum*10+(s[i]-'A'-(s[i]>'Q'))/3+2;
            }
    }
    return sum;
}

void Solution()
{
    int n;//输入次数
    cin>>n;
    int data[maxn];
    for(int i=0;i//输入
    {
          string s;
          cin>>s;
          data[i]=Hash(s);
    }
    sort(data,data+n);//排序归类
    for(int i=0,sum=1;i1;i++)//输出
    {
        while(data[i]==data[i+1])
        {
            sum++;
            i++;
        }
        if(sum>1)
        {
            printf("%d-%d  %d",data[i]/1000,data[i]%1000,sum);
        }
    }
}
int main()
{
    Solution();
    system("pause");
}

你可能感兴趣的:(简单算法)