Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

改了又改,还是超时,AC的人帮忙看看,哪时出问题了,总超时?

Posted by ding_d at 2008-06-24 01:03:12 on Problem 1002
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;


int mapping(char c)
{
	if(c=='A'||c=='B'||c=='C'||c=='a'||c=='b'||c=='c') return 2;
	if(c=='D'||c=='E'||c=='F'||c=='d'||c=='e'||c=='f') return 3;
	if(c=='G'||c=='H'||c=='I'||c=='g'||c=='h'||c=='i') return 4;
	if(c=='J'||c=='K'||c=='L'||c=='j'||c=='k'||c=='l') return 5;
	if(c=='M'||c=='N'||c=='O'||c=='m'||c=='n'||c=='o') return 6;
	if(c=='P'||c=='R'||c=='S'||c=='p'||c=='r'||c=='s') return 7;
	if(c=='T'||c=='U'||c=='V'||c=='t'||c=='u'||c=='v') return 8;
	if(c=='W'||c=='X'||c=='Y'||c=='w'||c=='x'||c=='y') return 9;
	return c-'0';
}

int main()
{
	int m,n,p,s,t;
	int i=0,j,k,fla=0;
	int temp[100000],tem,b[100000];
	char a[50],res[100000];
	scanf("%d",&m);
	while(i<m)
	{
		scanf("%s",a);
		n = strlen(a);
		s=0;
		for(j=0;j<n;j++)
		{
			if(a[j] == '-')
				continue;
			t=mapping(a[j]);
			s=s*10+t;
		}
		b[i]=s;
		i++;
	}
	
	if(m>=0)
	sort(b,b+m);

	k=0;
	temp[k]=0;
	for(i=0;i<m;)
	{
		res[i]=1;
		for(j=i+1;j<m;j++)
		{
			if(b[i] != b[j])
			{
				k++;
				temp[k]=j;
				break;
			}
			res[i]++;
			fla=1;
		}	
		p=res[i];
		i=i+p;
	}
	
k++;
if(fla)
	for(i=0;i<k;i++)
	{
		j=temp[i];
		if(res[j]>1)
		{
			p=b[j]/10000;
			printf("%.3d-",p);
			p=b[j]%10000;
			printf("%.4d",p);
			printf(" %d\n",res[j]);
		}
	}

else
	printf("No duplicates.\n");

	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator