64,642
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include<cstring>
using namespace std;
const char map[] = {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};
typedef char (*Tel)[16];
int Deal(Tel telephone, Tel result, int count[], int nCases);
void Output(Tel result, int count[], int nCount);
int main()
{
int nCases;
int index = 0;
cin >> nCases;
Tel telephone = new char[nCases][16];
Tel result = new char[nCases][16];
int *count = new int[nCases];
char temp[16];
while (index < nCases)
{
cin >> temp;
strcmp(telephone[index++], temp);
}
int nCount = Deal(telephone, result, count, nCases);
Output(result, count, nCount);
delete []count;
delete []telephone;
delete []result;
return 0;
}
int Deal(Tel telephone, Tel result, int count[], int nCases)
{
char temp[16];
int nCount = 0;
temp[8] = '\0';
for (int i = 0; i < nCases; i++)
count[i] = 0;
for (int i = 0; i < nCases; i++)
{
int len = strlen(telephone[i]);
int k = 0;
int j;
for (j = 0; j < len; j++)
{
if (telephone[i][j] != '-')
temp[k++] = map[telephone[i][j]-'A'];
if (k == 3)
temp[k++] = '-';
}
for (j = 0; j < nCount; j++)
if (strcmp(temp, result[j]) == 0)
{
count[j]++;
break;
}
if (j == nCount) {
strcpy(result[nCount++], temp);
count[nCount-1]++;
}
}
return nCount;
}
void output(Tel result, int count[], int nCount)
{
for (int i = 0; i < nCount; i++)
cout << result[i] << " " << count[i] << endl;
}