首先将输入改写成数据,然后查找+排序输出。
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;
int main() {
int N(0);
cin >> N;
vector<string> ivec;
for (int i = 0; i != N; i++) {
string str;
cin >> str;
ivec.push_back(str);
}
for (int i = 0; i != N; i++) {
string strtemp = ivec[i];
string newstr;
for (int j = 0; j != strtemp.length(); j++) {
if (strtemp[j] == 65 || strtemp[j] == 66 || strtemp[j] == 67) {
newstr += '2';
} else if (strtemp[j] == 68 || strtemp[j] == 69 || strtemp[j] == 70) {
newstr += '3';
} else if (strtemp[j] == 71 || strtemp[j] == 72 || strtemp[j] == 73) {
newstr += '4';
} else if (strtemp[j] == 74 || strtemp[j] == 75 || strtemp[j] == 76) {
newstr += '5';
} else if (strtemp[j] == 77 || strtemp[j] == 78 || strtemp[j] == 79) {
newstr += '6';
} else if (strtemp[j] == 80 || strtemp[j] == 82 || strtemp[j] == 83) {
newstr += '7';
} else if (strtemp[j] == 84 || strtemp[j] == 85 || strtemp[j] == 86) {
newstr += '8';
} else if (strtemp[j] == 87 || strtemp[j] == 88 || strtemp[j] == 89) {
newstr += '9';
} else if (strtemp[j] == 45) {
newstr = newstr;
} else {
newstr += strtemp[j];
}
}
newstr.insert(3, 1, '-');
ivec[i] = newstr;
}
map<string, int> imap;
for (vector<string>::iterator iter = ivec.begin(); iter != ivec.end(); iter++) {
++imap[*iter];
}
bool cout_flag(false);
for (map<string, int>::iterator iter = imap.begin(); iter != imap.end(); iter++) {
if ((iter->second) > 1) {
cout << iter->first << " " << iter->second << endl;
cout_flag = true;
}
}
if (!cout_flag) {
cout << "No duplicates.";
}
}