| ||||||||||
| 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 | |||||||||
真不知道為什麼會Time Limit Exceeded,無語了#include <iostream>
#include <list>
#include <string>
#include <map>
#include <algorithm>
// #include <Windows.h>
inline void translate(const std::map<char, char>& table, const std::string& input, std::string& output);
int main() {
int n = 0;
std::cin>>n;
// DWORD t = GetTickCount();
std::list<std::string> strs;
std::map<std::string, int> mv;
std::map<char, char> table;
table['A'] = table['B'] = table['C'] = '2';
table['D'] = table['E'] = table['F'] = '3';
table['G'] = table['H'] = table['I'] = '4';
table['J'] = table['K'] = table['L'] = '5';
table['M'] = table['N'] = table['O'] = '6';
table['P'] = table['R'] = table['S'] = '7';
table['T'] = table['U'] = table['V'] = '8';
table['W'] = table['X'] = table['Y'] = '9';
std::string input;
std::string output;
while(std::cin>>input) {
if(n -- > 0) {
translate(table, input, output);
strs.push_back(output);
mv[output] ++;
} else {
break;
}
}
// std::cout<<"---"<<GetTickCount() - t<<std::endl;
{
strs.clear();
std::map<std::string, int>::const_iterator it = mv.begin();
std::map<std::string, int>::const_iterator end = mv.end();
while(it != end) {
strs.push_back(it->first);
it ++;
}
strs.sort();
}
std::list<std::string>::const_iterator it = strs.begin();
std::list<std::string>::const_iterator end = strs.end();
bool has_duplicate = false;
while(it != end) {
if (mv[*it] > 1) {
std::cout<<*it<<" "<<mv[*it]<<std::endl;
has_duplicate = true;
}
it ++;
}
if (!has_duplicate)
std::cout<<"No duplicates. "<<std::endl;
// std::cout<<GetTickCount() - t<<std::endl;
return 0;
}
inline void translate(const std::map<char, char>& table, const std::string& input, std::string& output) {
output.resize(8);
char* pHeader = &output[0];
char* p = pHeader;
for(int i = 0; i < (int)input.size() && p - pHeader < 8; i ++) {
char c = input[i];
if (c >= '0' && c <= '9') {
*(p++) = c;
} else if (c >= 'A' && c <= 'Z') {
std::map<char, char>::const_iterator it = table.find(c);
if (it != table.end())
*(p++) = it->second;
}
if (p - pHeader == 3)
*(p++) = '-';
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator