题目链接:
http://poj.org/problem?id=1002
大致题意:
中文题。。
思路:
简单的模拟 + 排序
#include <iostream>
using namespace std;
const int maxn = 200000;
int a[1024];
char s1[256], s[maxn][55];
int cmp(const void *a, const void *b)
{
char *x = (char *)a;
char *y = (char *)b;
return strcmp(x, y);
}
int main()
{
// FILE *p = fopen("input.txt", "r");
a['A'] = a['B'] = a['C'] = 2;
a['D'] = a['E'] = a['F'] = 3;
a['G'] = a['H'] = a['I'] = 4;
a['J'] = a['K'] = a['L'] = 5;
a['M'] = a['N'] = a['O'] = 6;
a['P'] = a['R'] = a['S'] = 7;
a['T'] = a['U'] = a['V'] = 8;
a['W'] = a['X'] = a['Y'] = 9;
int i, j, k, n;
scanf("%d", &n);
for (k = 1; k <= n; ++k)
{
scanf("%s", s1);
for (i = 0, j = 0; s1[i]; ++i)
{
if (s1[i] != '-')
{
s[k][j] = s1[i];
if (s[k][j] >= 'A' && s[k][j] <= 'Z')
s[k][j] = a[s[k][j]] + '0';
++j;
}
}
}
qsort(s + 1, n, sizeof(s[1]), cmp);
int cnt = 1, flag = 0;
for (i = 1; i <= n; ++i)
{
if (strcmp(s[i], s[i + 1]) != 0)
{
if (cnt >= 2)
{
flag = 1;
printf("%c%c%c-%c%c%c%c %d\n", s[i][0], s[i][1], s[i][2], s[i][3], s[i][4], s[i][5], s[i][6], cnt);
}
cnt = 1;
}
else
++cnt;
}
if (!flag)
printf("No duplicates.\n");
return 0;
}