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

太悲剧了……老TLE……

Posted by Lighting at 2009-05-03 21:24:16 on Problem 1002
#include <iostream>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

char Trans( char c )
{
	switch ( c )
	{
	case 'A':
	case 'B':
	case 'C':
		return '2';

	case 'D':
	case 'E':
	case 'F':
		return '3';

	case 'G':
	case 'H':
	case 'I':
		return '4';

	case 'J':
	case 'K':
	case 'L':
		return '5';

	case 'M':
	case 'N':
	case 'O':
		return '6';

	case 'P':
	case 'R':
	case 'S':
		return '7';

	case 'T':
	case 'U':
	case 'V':
		return '8';

	case 'W':
	case 'X':
	case 'Y':
		return '9';
	}

	return c;
}

void Convert( string &str )
{
	static string s;
	int i = 0 , j = 0;
	s.resize( 7 );
	while ( i < 7 )
	{
		if ( str[j] == '-' )
		{
			j++;
			continue;
		}
		s[i] = Trans( str[j] );
		i++;
		j++;
	}
	s.insert( s.begin() + 3 , '-' );

	str =  s;
}

bool MyFind( const  pair<string , int> &e )
{
	return e.second > 1;
}

int main()
{
	map<string , int> m;
	map<string , int>::iterator iter;
	int T;
	string str;
	cin>>T;
	str.reserve( 200 );
	while ( T-- > 0 )
	{
		cin>>str;
		Convert( str );
		m[str]++;
	}

	iter = find_if( m.begin() , m.end() , MyFind );
	if ( iter == m.end() )
	{
		cout<<"No duplicates."<<endl;
	}
	else
	{
		iter = m.begin();
		while ( iter != m.end() )
		{
			if ( iter->second > 1 )
			{
				cout<<iter->first<<" "<<iter->second<<endl;
			}
			iter++;
		}
	}



	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