UVA-755

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <map>
#define DEBUG
#ifndef DEBUG
#include <fstream>
#define cout fff
ofstream fff("E:/out.txt",std::ios::out);
#endif

using namespace std;

//c++ string类会返回字符,可以 s[k]-'A' 进行映射
int mapper[26]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,-1,7,7,8,8,8,9,9,9,-1}; 
string s;
map<string,int> m;
int main(){
    int n,x,flg;
    cin>>n;
    for(int i=0;i<n;i++){
        flg=0;
        cin>>x;
        m.clear();
        for(int j=0;j<x;j++){
            cin>>s;
            int ll=0;
//c++ string类的erase,如果erase(0)指的是删除从零开始包括0删除到最后,相当于erase(0,length);
            while (ll<s.length())
            {
                if(s[ll]=='-') s.erase(ll,1);
                else if(isalpha(s[ll])){
                    s[ll]=char(mapper[s[ll]-'A']+'0');//不能 s[ll++]
                    ll++;
                }else ll++;
            }
            s.insert(3,"-");
            if(m.count(s)!=0){
                m[s]=m[s]+1;
                flg=1;
            }
            else m[s]=1;
        }
        if(flg){
            for(map<string,int>::iterator pq=m.begin();pq!=m.end();pq++)
                if(pq->second!=1)
                    cout<<pq->first<<' '<<pq->second<<endl;
        }
        else cout<<"No duplicates.
";
        if(i!=n-1) cout<<endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/MorrowWind/p/13056515.html