情急之下用了map,之前因为几个bugWA了一版,又因为用了快排和遍历T了一版。
POJ的数据比原题的数据强的多,可以使用gets和map来进一步优化。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <queue>
#include <utility>
using namespace std;
struct tele
{
char str_arr[300];
int len, val, no, same;
void init()
{
memset(str_arr, 0, sizeof(str_arr));
len = val = no = same = 0;
}
void getlen()
{
len = strlen(str_arr);
}
void make()
{
int i = 0;
while(str_arr[i] != '\0')
{
if(str_arr[i] == 'Q' || str_arr[i] == 'Z' || str_arr[i] == '-')
{
for(int j = i; j < len - 1; ++j)
{
str_arr[j] = str_arr[j + 1];
}
len -= 1;
str_arr[len] = '\0';
}
else i += 1;
}
// cout << "done " << endl;
len = 7;
for(int k = 0; k < len; ++k)
{
if(str_arr[k] == 'A' || str_arr[k] == 'B' || str_arr[k] == 'C')
{
str_arr[k] = '2';
}
else if(str_arr[k] == 'D' || str_arr[k] == 'E' || str_arr[k] == 'F')
{
str_arr[k] = '3';
}
else if(str_arr[k] == 'G' || str_arr[k] == 'H' || str_arr[k] == 'I')
{
str_arr[k] = '4';
}
else if(str_arr[k] == 'J' || str_arr[k] == 'K' || str_arr[k] == 'L')
{
str_arr[k] = '5';
}
else if(str_arr[k] == 'M' || str_arr[k] == 'N' || str_arr[k] == 'O')
{
str_arr[k] = '6';
}
else if(str_arr[k] == 'P' || str_arr[k] == 'S' || str_arr[k] == 'R')
{
str_arr[k] = '7';
}
else if(str_arr[k] == 'T' || str_arr[k] == 'U' || str_arr[k] == 'V')
{
str_arr[k] = '8';
}
else if(str_arr[k] == 'W' || str_arr[k] == 'X' || str_arr[k] == 'Y')
{
str_arr[k] = '9';
}
}
for(i = 7; i >= 3; --i)
{
str_arr[i] = str_arr[i - 1];
}
str_arr[3] = '-', str_arr[8] = '\0';
}
};
tele base_elem[100117];
map<string, int> sol_map;
int main()
{
int n, i, j, k;
scanf("%d", &n);
{
getchar();
for(i = 0; i < n; ++i)
{
base_elem[i].init();
gets(base_elem[i].str_arr);
base_elem[i].getlen();
base_elem[i].make();
string tmp = base_elem[i].str_arr;
sol_map[tmp] += 1;
}
int maxc = 1;
map<string, int>::iterator iter;
for(iter = sol_map.begin(); iter != sol_map.end(); ++iter)
{
if(iter->second > maxc)
{
maxc = iter->second;
}
}
if(maxc == 1)
{
printf("No duplicates. \n");
}
else
{
for(iter = sol_map.begin(); iter != sol_map.end(); ++iter)
{
if(iter->second > 1)
{
cout << iter->first << " " << iter->second << endl;
}
}
}
}
return 0;
}