C++用两个map完成编程

img

#include <iostream>
#include <map>
#include <string>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main() {
    map<char,char> letter_digit={{'0','0'},{'1','1'},
                                {'A','2'},{'B','2'},{'C','2'},{'2','2'},
                                {'D','3'},{'E','3'},{'F','3'},{'3','3'},
                                {'G','4'},{'H','4'},{'I','4'},{'4','4'},
                                {'J','5'},{'K','5'},{'L','5'},{'5','5'},
                                {'M','6'},{'N','6'},{'O','6'},{'6','6'},
                                {'P','7'},{'Q','7'},{'R','7'},{'S','7'},{'7','7'},
                                {'T','8'},{'U','8'},{'V','8'},{'8','8'},
                                {'W','9'},{'X','9'},{'Y','9'},{'Z','9'},{'9','9'}};
    map<string,int> digit_times;
    int n,i,k;
    string s,t;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> s;  //读入每一行的字符串
        t="";
        string::size_type len=s.length();
        for(k=0;k<=len;k++){
            if(s[k]!='-'){
                t+=letter_digit[s[k]];
            }
        }  //每一行内的计算 
        t.insert(4,"-");  //4和5之间插入'-' 
        digit_times[t]++;
    }
        for(auto a:digit_times)
            cout << a.first << " " << a.second << endl;
    return 0;
}