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

STL:MAP TLE! 囧

Posted by ayaya at 2007-03-15 16:11:00 on Problem 1002
#include <iostream>
#include <map>
#include <string>
using namespace std;

typedef map<string,int,less<string> > NumberType;
typedef map<string,int,less<string> >::iterator NumberType_IT;

NumberType Dict;

void check(string &Number)
{
	int pos=Number.find_first_of('-');
	while (pos>-1)
	{
		Number.erase(pos,1);
		pos=Number.find_first_of('-');
	}
	for (int i=0;i<Number.length();i++)
	{
		switch (Number[i])
		{
			case 'A' :
			case 'B' :
			case 'C' : Number[i]='2';
				       break;
			case 'D' :
			case 'E' :
			case 'F' : Number[i]='3';
					   break;
			case 'G' :
			case 'H' :
			case 'I' : Number[i]='4';
				       break;
			case 'J' :
			case 'K' :
			case 'L' : Number[i]='5';
				       break;
			case 'M' : 
			case 'N' :
			case 'O' : Number[i]='6';
				       break;
			case 'P' :
			case 'R' :
			case 'S' : Number[i]='7';
				       break;
			case 'T' :
			case 'U' :
			case 'V' : Number[i]='8';
				       break;
			case 'W' :
			case 'X' :
			case 'Y' : Number[i]='9';
				       break;
		}
	}
	Number.insert(3,"-");
}

int main()
{
	int n;
	cin >> n;
	for (int i=0;i<n;i++)
	{
		string Number;
		cin >> Number;
		check(Number);
		NumberType_IT it;
		Dict[Number]++;
	}
	int flag=0;
	for (NumberType_IT it=Dict.begin();it!=Dict.end();it++)
	{
		if (it->second>1)
		{
			cout << (it->first) << ' ' << (it->second) << endl;
			flag++;
		}
	}
	if (flag==0) cout << "No duplicates.";
	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