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

超时的问题,哪位大神可以帮帮忙~~~

Posted by 1416006 at 2015-04-24 11:26:37 on Problem 1002
#include<iostream>
#include<map>
#include<string>
using namespace std;

char *remove_change(string str);
char change(char c);

int main()
{
    int n;
	cin>>n;
	cin.ignore();
	string str;
	char *restr;
	map<string,int> m;
	map<string,int>::iterator iter;
	for(int i=0;i<n;i++)
	{
		getline(cin,str);
		restr=remove_change(str);
		iter=m.begin();
		while(iter!=m.end()&&restr>iter->first)
			iter++;
		if(iter!=m.end()&&restr==iter->first)
			iter->second++;
		else
			m.insert(iter,map<string,int>::value_type(restr,1));
	}
	//输出
	iter=m.begin();
	bool tag=true;
	while(iter!=m.end())
	{
		if(iter->second>1)
		{
			tag=false;
			str=iter->first;
			for(int i=0;i<str.length();i++)
			{
				cout<<str[i];
				if(i==2) cout<<'-';
			}
			cout<<" "<<iter->second<<endl;
		}
		iter++;
	}
	if(tag) cout<<"No duplicates.\n";
	return 0;
}

char *remove_change(string str)
{
	char *temp;
	temp=new char[7];
	int j=0;
	for(int i=0;i<str.length();i++)
	{
		if('-'==str[i])
			continue;
		if(str[i]>='0'&&str[i]<='9')
			temp[j]=str[i];
		else
			temp[j]=change(str[i]);
		j++;
	}
	temp[j]='\0';
	return temp;
}

char change(char c)
{
	char temp;
	switch(c)
	{
	case 'A':case 'B':case 'C': 
		temp='2';break;
	case 'D':case 'E':case 'F':
		temp='3';break;
	case 'G':case 'H':case 'I':
		temp='4';break;
	case 'J':case 'K':case 'L':
		temp='5';break;
	case 'M':case 'N':case 'O':
		temp='6';break;
	case 'P':case 'R':case 'S':
		temp='7';break;
	case 'T':case 'U':case 'V':
		temp='8';break;
	case 'W':case 'X':case 'Y':
		temp='9';break;
	}
	return temp;
}

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