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 EXCEEDIn Reply To:大牛们帮忙看看怎么老是TIME LIMIT EXCEED Posted by:singingbear at 2009-08-28 12:45:51 首先声明偶不是大牛 你这个需要把string改成char cin改成scanf 这样的话用map可以险过,如果考虑优化,也不要用map > 程序很简单,自己考虑了半天,没发现效率特别差的地方,也试着改过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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator