[POJ]1002 487-3279

首先将输入改写成数据,然后查找+排序输出。

#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.";
    }
} 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值