| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:大牛们帮帮忙啊,为什么老是TIME LIMIT EXCEEDED?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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator