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 EXCEED

Posted by yuanyuelang at 2009-08-31 22:59:30 on Problem 1002
In Reply To:大牛们帮忙看看怎么老是TIME LIMIT EXCEED Posted by:singingbear at 2009-08-28 12:45:51
> 程序很简单,自己考虑了半天,没发现效率特别差的地方,也试着改过if为switch,也一样超时,不知道为什么。
> 程序如下:
> #include <iostream>
> #include <map>
> 
> using namespace std;
> 
> int main()
> {
>     map<string, int> result;
>     map<string, int>::iterator pResult;
>     
>     int phoneNum;
>     string phone;
> 
>     cin >> phoneNum;
>     for(int i=0; i<phoneNum; i++)
>     {
>         cin >> phone;
>         
>         string temp;
>         for(int j=0; j<phone.length(); j++)
>         {
>             char c = phone.at(j);
>             if (c >= '0' && c <= '9')
>             {
>                 temp += c;
>             }
>             else if (c=='A' || c=='B' || c=='C')
>             {
>                 temp += "2";
>             }
>             else if (c=='D' || c=='E' || c=='F')
>             {
>                 temp += "3";
>             }
>             else if (c=='G' || c=='H' || c=='I')
>             {
>                 temp += "4";
>             }
>             else if (c=='J' || c=='K' || c=='L')
>             {
>                 temp += "5";
>             }
>             else if (c=='M' || c=='N' || c=='O')
>             {
>                 temp += "6";
>             }
>             else if (c=='P' || c=='R' || c=='S')
>             {
>                 temp += "7";
>             }
>             else if (c=='T' || c=='U' || c=='V')
>             {
>                 temp += "8";
>             }
>             else if (c=='W' || c=='X' || c=='Y')
>             {
>                 temp += "9";
>             }
>         }
>         temp.insert(3, 1, '-');
>         ++result[temp];
>     }
>     
>     bool tag = false;
>     for(pResult=result.begin(); pResult!=result.end(); pResult++)
>     {
>         if(pResult->second > 1)
>         {
>             cout << pResult->first << " " << pResult->second << endl;
>             tag = true;
>         }
>     }
>     if (!tag)
>         cout << "No duplicates." << endl;
> }

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