487-3279(1002)

#pragma warning (disable:4786)
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

typedef struct
{
string first;
int second;
}res;

bool less_first(res tmp1,res tmp2)
{
return tmp1.first<tmp2.first;
}

bool my_equal(res tmp1,res tmp2)
{
return tmp1.first==tmp2.first;
}

void main()
{
map<char,char> li;
map<char,char>::iterator mit;
li['A']='2';li['B']='2';li['C']='2';
li['D']='3';li['E']='3';li['F']='3';
li['G']='4';li['H']='4';li['I']='4';
li['J']='5';li['K']='5';li['L']='5';
li['M']='6';li['N']='6';li['O']='6';
li['P']='7';li['R']='7';li['S']='7';
li['T']='8';li['U']='8';li['V']='8';
li['W']='9';li['X']='9';li['Y']='9';
int line;
cin>>line;
string temp;
vector<string> str;
vector<string>::iterator sit;
string::iterator strit;

int i;
for (i=0;i<line;i++)
{
cin>>temp;
str.push_back(temp);
}

for (sit=str.begin();sit!=str.end();sit++)
{
strit=remove(sit->begin(),sit->end(),'-');
sit->erase(strit,sit->end());
}

for (sit=str.begin();sit!=str.end();sit++)
for (mit=li.begin();mit!=li.end();mit++)
for (strit=sit->begin();strit!=sit->end();strit++)
if (*strit==mit->first)
*strit=mit->second;

res tmp;
vector<res> result;
vector<res>::iterator resit;

int num;
int j;
for (i=0;i<str.size()-1;i++)
{
num=1;
temp=str[i];
for (j=i+1;j<str.size();j++)
{
if (temp==str[j])
{
num++;
}
}
if (num!=1)
{
tmp.first=temp;
tmp.second=num;
result.push_back(tmp);
}
}
if (result.empty())
{
cout<<"No duplicates."<<endl;
}
else
{
sort(result.begin(),result.end(),less_first);
result.erase(unique(result.begin(),result.end(),my_equal),result.end());
for (resit=result.begin();resit!=result.end();resit++)
{
resit->first.insert(resit->first.begin()+3,1,'-');
cout<<resit->first<<""<<resit->second<<endl;
}
}
}

你可能感兴趣的:(487-3279(1002))