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:用C++STL写好容易超时啊

Posted by yesbaba at 2007-06-12 15:07:59 on Problem 1002
In Reply To:用C++STL写好容易超时啊 Posted by:undiaoyao at 2006-12-20 20:02:47
用map<int, int>好点吧

> C++STL写思路蛮自然也方便……就是超时得厉害
> 郁闷……
> 
> #include <iostream>
> #include <vector>
> #include <map>
> 
> using namespace std;
> 
> void delcon(string &str)
> {
>     int index = 0;
>     while(index < str.length())
>     {
>         if(str[index] == '-')
>         {
>             str.erase(index,1);
>             continue;
>         }
>         ++index;
>     }
> }
> 
> void pout_book(map<string, int> telbook)
> {
>      map<string, int>::iterator bookIter = telbook.begin();
>      for(;bookIter != telbook.end(); ++bookIter)
>      {
>          string tempStr = bookIter->first;
>          if(bookIter->second>1)
>          {
>              tempStr.insert(3,"-");
>              cout<<tempStr<<" "<<bookIter->second<<endl;
>          }
>      }
> }
> 
> void trance(string &str)
> {
>      for(int index=0; index < str.length(); ++index)
>      {
>          switch(str[index]){
>              case 'A':case 'B':case 'C':
>                  (str[index]) = '2';break;
>              case 'D':case 'E':case 'F':
>                  (str[index]) = '3';break;
>              case 'G':case 'H':case 'I':
>                  (str[index]) = '4';break;
>              case 'J':case 'K':case 'L':
>                  (str[index]) = '5';break;
>              case 'M':case 'N':case 'O':
>                  (str[index]) = '6';break;
>              case 'P':case 'R':case 'S':
>                  (str[index]) = '7';break;
>              case 'T':case 'U':case 'V':
>                  (str[index]) = '8';break;
>              case 'W':case 'X':case 'Y':
>                  (str[index]) = '9';break;
>              default:break;
>          }
>      }
> }
> 
> int main()
> {
>     int turns = 0;
>     map<string,int> telBook;
>     cin>>turns;
>     for(;turns > 0; --turns)
>     {
>         string curStr("");
>         cin>>curStr;
>         delcon(curStr);
>         trance(curStr);
>         ++telBook[curStr];
>     }
>     pout_book(telBook);
> }

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