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 20121181jj at 2014-05-02 11:23:32 on Problem 1002
In Reply To:真不知道為什麼會Time Limit Exceeded,無語了 Posted by:nowaits at 2014-04-19 19:23:06
> #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:
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