#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <cctype>
using namespace std;
int n;
char s[50];
int hash[10000000]; //一对一的hash表,10000000勉强能过,也可开个n大的表再排序;
int transform(char c)
{
if (isdigit(c)) return c-'0';
if (c<='C') return 2;
if (c<='F') return 3;
if (c<='I') return 4;
if (c<='L') return 5;
if (c<='O') return 6;
if (c<='S') return 7;
if (c<='V') return 8;
if (c<='Y') return 9;
}
void chuli(char s[])
{
int x=0,k=0;
for (int i=0; s[i] && k<7; i++)
if (isalpha(s[i]) || isdigit(s[i]) && s[i]!='Q' && s[i]!='Z')
{
k++;
int y=transform(s[i]);
x=x*10+y;
}
hash[x]++;
}
int main()
{
scanf("%d",&n);
getchar();
for (int i=0; i<10000000; i++) hash[i]=0;
for (int i=1; i<=n; i++)
{
gets(s);
chuli(s);
}
bool mark=false;
for (int i=0; i<10000000; i++)
{
if (hash[i]>1)
{
printf("%03d-%04d %d\n",i/10000,i%10000,hash[i]); //注意格式,如001-0000的情况
mark=true;
}
}
if (!mark) printf("No duplicates.\n"); //别忘了
return 0;
}
POJ1002-纯净水题,注意题目要求
最新推荐文章于 2017-08-07 22:34:15 发布