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:郁闷,偷懒用STL不行啊,超时.难道这道题不能用STL么In Reply To:郁闷,偷懒用STL不行啊,超时.难道这道题不能用STL么 Posted by:acm_primer2007 at 2007-10-06 22:05:56 > #include <iostream> > #include <string> > #include <vector> > #include <iterator> > #include <set> > #include <algorithm> > using namespace std; > > string fun(string &num) > { > string res=""; > > for(int i=num.length()-1; i>=0; i--) > { > switch(num[i]) { > case 'A': > case 'B': > case 'C': > res.insert(res.begin(),'2'); > break; > case 'D': > case 'E': > case 'F': > res.insert(res.begin(),'3'); > break; > case 'G': > case 'H': > case 'I': > res.insert(res.begin(),'4'); > break; > case 'J': > case 'K': > case 'L': > res.insert(res.begin(),'5'); > break; > case 'M': > case 'N': > case 'O': > res.insert(res.begin(),'6'); > break; > case 'P': > case 'R': > case 'S': > res.insert(res.begin(),'7'); > break; > case 'T': > case 'U': > case 'V': > res.insert(res.begin(),'8'); > break; > case 'W': > case 'X': > case 'Y': > res.insert(res.begin(),'9'); > break; > case '-': > break; > default: > res.insert(res.begin(),num[i]); > break; > } > } > res.insert(res.begin()+3,'-'); > return res; > } > > void main() > { > > string temp; > vector<string> number; > set<string> unique_number; > > int n; > cin>>n; > for(int i=0; i<n; i++) > { > cin>>temp; > number.push_back( fun(temp) ); > unique_number.insert(fun(temp)); > > } > > sort(number.begin(),number.end()); > > > > for(set<string>::iterator sp=unique_number.begin(); sp!=unique_number.end(); sp++) > { > int cnt = count(number.begin(),number.end(),*sp); > if(cnt>1) > { > cout<<*sp<<" "; > cout<<cnt<<endl; > } > > > } > > > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator