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不行啊,超时.难道这道题不能用STL么

Posted by acm_primer2007 at 2007-10-06 22:05:56 on Problem 1002
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <set>
#include <algorithm>
using namespace std;

string fun(string &num)
{
	string res="";

	for(int i=num.length()-1; i>=0; i--)
	{
		switch(num[i]) {
		case 'A':
		case 'B':
		case 'C':
			res.insert(res.begin(),'2');
			break;
		case 'D':
		case 'E':
		case 'F':
			res.insert(res.begin(),'3');
			break;
		case 'G':
		case 'H':
		case 'I':
			res.insert(res.begin(),'4');
			break;
		case 'J':
		case 'K':
		case 'L':
			res.insert(res.begin(),'5');
			break;
		case 'M':
		case 'N':
		case 'O':
			res.insert(res.begin(),'6');
			break;
		case 'P':
		case 'R':
		case 'S':
			res.insert(res.begin(),'7');
			break;
		case 'T':
		case 'U':
		case 'V':
			res.insert(res.begin(),'8');
			break;
		case 'W':
		case 'X':
		case 'Y':
			res.insert(res.begin(),'9');
			break;
		case '-':
			break;
		default:
			res.insert(res.begin(),num[i]);
			break;
		}
	}
	res.insert(res.begin()+3,'-');
	return res;
}

void main()
{
	
	string temp;
	vector<string> number;
	set<string> unique_number;
		
	int n;
	cin>>n;
	for(int i=0; i<n; i++)
	{
		cin>>temp;
		number.push_back( fun(temp) );
		unique_number.insert(fun(temp));

	}

	sort(number.begin(),number.end());

	

	for(set<string>::iterator sp=unique_number.begin(); sp!=unique_number.end(); sp++)
	{
		int cnt = count(number.begin(),number.end(),*sp);
		if(cnt>1)
		{
			cout<<*sp<<" ";
			cout<<cnt<<endl;
		}
		
		
	}
	

}

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