33,321
社区成员




int main( )
{
map<char,int> m;
map<string,int>m2;
char g[256]={0};
char s[256]={0};
m['A']=m['B']=m['C']=2;
m['D']=m['E']=m['F']=3;
m['G']=m['H']=m['I']=4;
m['J']=m['K']=m['L']=5;
m['M']=m['N']=m['O']=6;
m['P']=m['Q']=m['R']=m['S']=7;
m['T']=m['U']=m['V']=8;
m['W']=m['X']=m['Y']=m['Z']=9;
int count=0;
cout<<"请输入电话号码的总个数\n";
cin>>count;
for (int i=0;i<count;i++)
{
cin>>s;
int l=0;
for (int j=0;s[j]!='\0';j++)
{
auto it=m.find(s[j]);
if (it!=m.end())
{
g[l]=it->second+48;
}
else
{
if (g[l]=='-')
{
g[l++]='-';
continue;
}
else
g[l]=s[j];
}
++l;
}
auto ic=m2.find(g);
if (ic!=m2.end())
ic->second+=1;
else
m2.insert(make_pair(g,1));
}
cout<<endl;
for_each(m2.begin(),m2.end(),[](pair<string,int> pa)
{
cout<<"转换后的电话号码: "<<pa.first<<"\t"<<"出现的次数:"<<pa.second<<endl;
});
}
#include<iostream>
#include<map>
#include<string>
using namespace std;
int main()
{
map<char,int>m;
map < char,int >::iterator iter;
map<string,int>n;
map < string,int >::iterator ite;
char s[256] = {0},g[256] = {0};
int i,j,t,l;
m['A']=m['B']=m['C']=2;
m['D']=m['E']=m['F']=3;
m['G']=m['H']=m['I']=4;
m['J']=m['K']=m['L']=5;
m['M']=m['N']=m['O']=6;
m['P']=m['Q']=m['R']=m['S']=7;
m['T']=m['U']=m['V']=8;
m['W']=m['X']=m['Y']=m['Z']=9;
cin>>t;
for(i=0;i<t;i++)
{
//getline(cin,s);
cin>>s;
l=0;
for(j=0;s[j]!='0';j++)
{
if(s[j]=='-')
break;
iter = m.find(s[j]);
if (iter != m.end())
g[l]=iter->second+48;
l++;
if(l==4)
{
g[l]='-';
l++;
}
}
n.insert(pair<string,int>(g,i));
}
for (ite = n.begin(); ite != n.end(); ite++ )
{
cout<< ite->first << " " << ite-> second << " " << endl;
}
system("PAUSE");
return 0;
}
注意:输入字符是大写的!!