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

一直报Time Limited Exceed,大神们帮看看能怎么优化?是STL使用的问题吗?

Posted by chancerly at 2013-11-16 22:19:43 on Problem 1002
代码如下:

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

char maptable[]={'2','2','2','3','3','3','4','4','4','5','5','5','6','6','6','7','-1','7','7','8','8','8','9','9','9','-1'};

bool ifAlphToDec(const char& alph, char& dec)
{
	if(!isalpha(alph))
		return false;
	else
	{
        dec = maptable[alph - 'A'];
        return true;
    }
}

int TransToStd(string& input, string& output )
{
	for(int i=0; i<input.size(); ++i)
	{
		char digit;			
		if(ifAlphToDec(input[i],digit))
		{
			if(output.size() == 3)
				output += '-';
			output += digit;
		}
		else if(input[i] == '-')
		{
			continue;
		}
		else
		{
			if(output.size() == 3)
				output += '-';
			output += input[i];				
		}
		
	}
}
int main()
{

	vector<string> Output;
	int num;
	cin >>num;
	for(int i=0; i < num; ++i)
	{
		string inputOneline;
		string outputOneline;
		cin >> inputOneline;
		TransToStd(inputOneline, outputOneline);
		Output.push_back(outputOneline);	
	}

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

	// output
	int dupnum = 1;
	vector<string>::iterator iter = Output.begin();
	bool Hasdup = false;
	while(iter != Output.end())
	{
		if((iter+1 != Output.end())&&(*iter == *(iter+1)))
		{
			dupnum++;
		}
		else
		{
			if(dupnum > 1)
			{
				cout << *iter << " " << dupnum << endl;
				Hasdup = true;
				dupnum = 1;

			}		
		}
		iter++;
	}
    if(!Hasdup)
        cout << "No duplicates." <<endl; 
    //system("pause");	
	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