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 |
tine limited probelm, help me,thank you!hi,i just want to know why my code is so slow. and can not pass time limited. thank you. my code is below: #include <iostream> #include <string> #include <vector> #include <set> using namespace std; int main(){ int num,i,j=0; char reader; set<string> container; vector<string> total; string s; s.reserve(8); int* ruler; cin>>num; ruler=new int(num); for(i=0;i<num;++i){ while(j<7&&cin>>reader){ if(reader!='-'){ ++j; switch(reader) { case 'A':reader='2';break; case 'B':reader='2';break; case 'C':reader='2';break; case 'D':reader='3';break; case 'E':reader='3';break; case 'F':reader='3';break; case 'G':reader='4';break; case 'H':reader='4';break; case 'I':reader='4';break; case 'J':reader='5';break; case 'K':reader='5';break; case 'L':reader='5';break; case 'M':reader='6';break; case 'N':reader='6';break; case 'O':reader='6';break; case 'P':reader='7';break; case 'R':reader='7';break; case 'S':reader='7';break; case 'T':reader='8';break; case 'U':reader='8';break; case 'V':reader='8';break; case 'W':reader='9';break; case 'X':reader='9';break; case 'Y':reader='9';break; default:; } if(j==4){ s=s+"-"; } s=s+reader; } } j=0; container.insert(s); total.push_back(s); s.erase(s.begin(),s.end()); } set<string>::const_iterator coll; for(coll=container.begin();coll!=container.end();++coll){ int k=0; vector<string>::const_iterator collv; for(collv=total.begin();collv!=total.end();++collv){ if(*coll==*collv){ ++k; } } if(k>1){ cout<<*coll<<' '<<k<<endl; } } return 1; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator