北大OJ1002

#include
#include
using namespace std;
char ch[]="22233344455566677778889999";
int compare(const void *lem1,const void *lem2)
{
	return (strcmp((char *)lem1,(char *)lem2));
}
int main()
{
	int cases,n,i=0,k,j;
	char chr[80],elems[100001][9];
	cin>>cases;
	n=cases;
	while(cases--)
	{
		k=j=0;
		cin>>chr;
		while(k<8)
		{
			if(chr[j]=='-')
			{
				j++;
				continue;
			}
			if(k==3)
			{
				elems[i][k++]='-';
				continue;
			}
			if(chr[j]>='A'&&chr[j]<='Z')
			{
					elems[i][k++]=ch[chr[j]-'A'];
					j++;
					continue;
			}
			if(chr[j]>='0'&&chr[j]<='9')
			{
					elems[i][k++]=chr[j];
					j++;
					continue;
			}
		}
		elems[i][k]='\0';
		i++;
	}
	qsort(elems,n,9,compare);
	bool key=true;
	i=0;
	while(i<n)
	{
		j=i;
		i++;
		while(i<n&&strcmp(elems[i],elems[j])==0)
			i++;
		if(i-j>1)
		{
			key=false;
			cout<<elems[j]<<" "<<i-j<<endl;
		}
	}	
	if(key)
			cout<<"No duplicates."<<endl;
	 return 0;
}

你可能感兴趣的:(算法)