1001 487-3279

一个模拟题,需要hash和sort一下

这代码在sdutoj上过了在poj上TLE

感觉时间复杂度没有问题,就是排序的nlogn

有一个很坑的地方No duplicates.

最后那个"."必须输出

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int n,i,flag[9999999],tel[100010],sum,x,p,count_;
string t;
struct jgt
{
	int bh;
	string s;
	int operator <(jgt a)const{ return bh= 'P'&&c <= 'S') return 7;
	if(c >= 'T'&&c <= 'V') return 8;
	return 9;
}
int main()
{
	scanf("%d",&n);
	for(i = 1;i <= n;i ++)
	{
		int tel_num = 0;
		sum = 0;
		t.clear();
		while(tel_num != 7)
		{
			scanf("%c",&c);
			if(c == '-'||c == '\n') continue;
			else 
			{
				tel_num ++;
				if(c >= 'A' && c<= 'Z') x = hash(c);
				else x = c-'0';
				t = t+char(x+'0');
				sum = sum*10+x;
			}
		}
		flag[sum] ++;
		if(flag[sum] == 2)
		{
			count_ ++;
			dl[count_].bh = sum;
			dl[count_].s = t;
		}
	}
	sort(dl+1,dl+count_+1);
	p = 0;
	for(i = 1;i <= count_;i ++)
	{
			p = 1;
			int j;
			for(j = 0;j <= 6;j ++)
			{
				printf("%c",dl[i].s[j]);
				if(j == 2) printf("-");
			}
			printf(" %d\n",flag[dl[i].bh]);
	}
	if(!p)	printf("No duplicates.");	
	return 0;
}


你可能感兴趣的:(stut,oj)