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

Re:大牛们帮帮忙啊,为什么老是TIME LIMIT EXCEEDED?

Posted by zhuizhuziwo at 2010-05-12 15:08:06 on Problem 1002
In Reply To:大牛们帮帮忙啊,为什么老是TIME LIMIT EXCEEDED? Posted by:lankeyouyin at 2009-10-10 23:46:10
靠 终于通过了。。真不容易啊。。。
关于超时,这里选择不实用字符流。。就可以降低时间了。。。


#include <fstream>
#include <string>
#include <sstream>
#include <iostream>
#include <map>

using namespace std;

const char mpChrDgt[26] = {'2','2','2',
'3','3','3',
'4','4','4',
'5','5','5',
'6','6','6',
'7','0','7','7',
'8','8','8',
'9','9','9','0'};

int main()
{
	int T = 0;
	string lineBuf;
	map<string, int> mpStrCnt;
	string dgtStr(8, '-');

	getline(cin, lineBuf);
	istringstream stream(lineBuf);
	stream>>T;
	
	for (int t = 0; t<T; t++)
	{
		getline(cin, lineBuf, '\n');
		char chr;
		int i=0;
		
		for (size_t j=0, size = lineBuf.size();j<size; j++)
		{
			chr = lineBuf[j];
			if ('A'<=chr && chr<='Z')
			{
				chr = mpChrDgt[chr-'A'];
			}
			else if(chr == '-')
				continue;

			dgtStr[i] = chr;
			if (i == 2)
			{
				i += 2;
				continue;
			}
			i++;
		}
		
		mpStrCnt[dgtStr]++;
	
	} //for

	map<string, int>::iterator iterMp = mpStrCnt.begin();
	bool hasDups = false;
	while (iterMp != mpStrCnt.end())
	{
		if (iterMp->second > 1)
		{
			cout << iterMp->first <<" "<<iterMp->second<<endl;
			hasDups = true;
		}
		iterMp++;
	}
	if (!hasDups)
	{
		cout <<"No duplicates."<<endl;
	}

	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