分析:简单的字符串处理然后判重,一开始sb了,还在想用什么数据结构,其实只要用快排就行
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char st[100];
int a[100010];
int main()
{
bool fff;
int n,tot,ii,sum,i,num,x,len;
scanf("%d",&n);
tot = 0;
for (ii = 1; ii <= n; ii++)
{
scanf("%s",st); len = strlen(st);
sum = 0;
for (i = 0; i < len; i++)
{
if (st[i] == '-' || st[i] == 'Q' || st[i] == 'Z') continue;
if (st[i] >= '0' && st[i] <= '9') x = st[i] - '0';
else
{
switch (st[i])
{
case 'A':case 'B':case 'C': x = 2; break;
case 'D':case 'E':case 'F': x = 3; break;
case 'G':case 'H':case 'I': x = 4; break;
case 'J':case 'K':case 'L': x = 5; break;
case 'M':case 'N':case 'O': x = 6; break;
case 'P':case 'R':case 'S': x = 7; break;
case 'T':case 'U':case 'V': x = 8; break;
case 'W':case 'X':case 'Y': x = 9; break;
}
}
sum = sum * 10 + x;
}
a[++tot] = sum;
}
sort(a+1,a+tot+1);
a[tot+1] = 99999999;
fff = true;
i = 0;
while (i < tot)
{
i++; num = 1;
while (a[i] == a[i+1])
{
fff = false;
num++;
i++;
}
if (num > 1)
{
printf("%03d-%04d %d\n",a[i]/10000,a[i]%10000,num);//学习别人的格式输出
}
}
if (fff == true) printf("No duplicates.\n");
return 0;
}