POJ1002,487-3279(STL)

直接map来模拟就好了。
代码如下:

#include<string>
#include<map>
#include<cstdio>
#include<iostream>
#include<cctype>
using namespace std;
map<string,int> mp;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		char s[30],s0[30];
		scanf("%s",s);
		int first=1,k=0;
		for(int j=0;s[j]!='\0';j++)
		{
			if(isdigit(s[j]))
			{
				s0[k++]=s[j];
			}
			else if(s[j]!='-')
			{
				if(s[j]>='A'&&s[j]<='C')
					s0[k++]='2';
				else if(s[j]>='D'&&s[j]<='F')
					s0[k++]='3';
				else if(s[j]>='G'&&s[j]<='I')
					s0[k++]='4';
				else if(s[j]>='J'&&s[j]<='L')
					s0[k++]='5';
				else if(s[j]>='M'&&s[j]<='O')
					s0[k++]='6';
				else if(s[j]>='P'&&s[j]<='S')
					s0[k++]='7';
				else if(s[j]>='T'&&s[j]<='V')
					s0[k++]='8';
				else if(s[j]>='W'&&s[j]<='Y')
					s0[k++]='9';
			}
			if(k==3)
				s0[k++]='-';
		}
		s0[k]='\0';//cout<<s0<<endl;
		string t;
		t=s0;
		if(mp.find(t)!=mp.end())
		{
			mp[t]++;
		}
		else	mp[t]=1;
	}
	int flag=0;
	for(map<string,int>::iterator it=mp.begin();it!=mp.end();++it)
	{
		if((*it).second>1)
		{
			cout<<(*it).first<<' '<<(*it).second<<endl;
			flag=1;
		}
	}
	if(!flag)
		cout<<"No duplicates.\n";
	return 0;
 } 

运行时间:985ms

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值