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

please help me.代码一直TLE,求解。

Posted by super_while at 2012-12-16 17:42:02 on Problem 1002 and last updated at 2012-12-16 17:45:15
代码一直Time Limit Exceeded,求解。 
#include <stdio.h>
#include <string>
#include <map>
using namespace std;
int main()
{
    int i, j, n=0, num, duplicates=0;
	size_t t=0;
	map<string, int> num_map;
	map<string, int>::iterator it;
    char src[200];
	scanf("%d", &num);
	while(n!=num)
	{
		scanf("%s", src);
		char *tra=src;
		char ch[200];
		i = 0;
		j = 0;
		do
		{
			if(*tra=='A'||*tra=='B'||*tra=='C')
				*tra = '2';
			else if(*tra=='D'||*tra=='E'||*tra=='F')
				*tra = '3';
			else if(*tra=='G'||*tra=='H'||*tra=='I')
				*tra = '4';
			else if(*tra=='J'||*tra=='K'||*tra=='L')
				*tra = '5';
			else if(*tra=='M'||*tra=='N'||*tra=='O')
				*tra = '6';
			else if(*tra=='P'||*tra=='R'||*tra=='S')
				*tra = '7';
			else if(*tra=='T'||*tra=='U'||*tra=='V')
				*tra = '8';
			else if(*tra=='W'||*tra=='X'||*tra=='Y')
				*tra = '9';
			else if(*tra=='0'||*tra=='1'||*tra=='2'||*tra=='3'||*tra=='4'||*tra=='5'||*tra=='6'||*tra=='7'||*tra=='8'||*tra=='9')
			    *tra =*tra;
			else {
				tra++;
				i++;
				ch[j]='\0';
				continue;
			}
			ch[j]=*tra;
			tra++;
			i++;
			j++;
            ch[j]='\0';
		}while(src[i]!='\0');

		n++;

		it=num_map.find(ch);
		if(it==num_map.end())
			num_map[ch]=1;
		else
			++(*it).second;
	}
    
	it=num_map.begin();
	for(i=0; i<num_map.size(); i++) { 
		if(it->second!=1) {
			printf("%c%c%c-%s %d\n", it->first[0], it->first[1], it->first[2], &(it->first[3]), it->second);
			duplicates=1;
		}
		it++;
	}

	if(duplicates==0)
		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