用G++超时,网上说C++时间短,然后就AC了。
/** \function:calculate if the telephone numbers are the same,
* output the numbers and the repeat times
* \param
* \param
* \return
*
*/
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
/*
bool small_to_big(map<string,int>::value_type pair1,map<string,int>::value_type pair2)
{
return pair1.first<pair2.first;
}
*/
int main()
{
int mount=0;//the mount of the numbers
map<string,int> numbers_times;
cin>>mount;
int i;
string src_numbers;
string::iterator iter;
for(i=0;i<mount;i++)
{
string temp_str;
cin>>src_numbers;
for(iter=src_numbers.begin();iter!=src_numbers.end();iter++)
{
if(*iter=='0') temp_str.push_back('0');
else if(*iter=='1') temp_str.push_back('1');
else if(*iter=='A'||*iter=='B'||*iter=='C'||*iter=='2') temp_str.push_back('2');
else if(*iter=='D'||*iter=='E'||*iter=='F'||*iter=='3') temp_str.push_back('3');
else if(*iter=='G'||*iter=='H'||*iter=='I'||*iter=='4') temp_str.push_back('4');
else if(*iter=='J'||*iter=='K'||*iter=='L'||*iter=='5') temp_str.push_back('5');
else if(*iter=='M'||*iter=='N'||*iter=='O'||*iter=='6') temp_str.push_back('6');
else if(*iter=='P'||*iter=='R'||*iter=='S'||*iter=='7') temp_str.push_back('7');
else if(*iter=='T'||*iter=='U'||*iter=='V'||*iter=='8') temp_str.push_back('8');
else if(*iter=='W'||*iter=='X'||*iter=='Y'||*iter=='9') temp_str.push_back('9');
else ; //do nothing
if(temp_str.size()==3) temp_str.push_back('-');
}
++numbers_times[temp_str];
}
map<string,int>::iterator iter_map;
vector<string> str;
for(iter_map=numbers_times.begin();iter_map!=numbers_times.end();iter_map++)
{
str.push_back(iter_map->first);
}
sort(str.begin(),str.end());
vector<string>::iterator iter_vec;
int flag=0;
for(iter_vec=str.begin();iter_vec!=str.end();iter_vec++)
{
if(numbers_times[*iter_vec]>1) {cout<<*iter_vec<<" "<<numbers_times[*iter_vec]<<endl;flag=1;}
}
if(flag==0) cout<<"No duplicates."<<endl;
return 0;
}