OJ百练1002 487-3279

<span style="font-family: Arial, Helvetica, sans-serif;">#include <iostream></span>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

bool judge(const char& ch)
{
    if(ch == '-')
        return true;
    else
        return false;
}

int main()
{
    int cnt;
    cin >> cnt;
    map<char, int> num;
    string temp;
    bool flag = true;
    map<string, int> vec;
    num['A'] = 2;
    num['B'] = 2;
    num['C'] = 2;
    num['D'] = 3;
    num['E'] = 3;
    num['F'] = 3;
    num['G'] = 4;
    num['H'] = 4;
    num['I'] = 4;
    num['J'] = 5;
    num['K'] = 5;
    num['L'] = 5;
    num['M'] = 6;
    num['N'] = 6;
    num['O'] = 6;
    num['P'] = 7;
    num['R'] = 7;
    num['S'] = 7;
    num['T'] = 8;
    num['U'] = 8;
    num['V'] = 8;
    num['W'] = 9;
    num['X'] = 9;
    num['Y'] = 9;
    while (cnt--)
    {
        cin >> temp;

        temp.erase(remove_if(temp.begin(), temp.end(), judge), temp.end());

       for (size_t i = 0; i < temp.size(); ++i)
            if (isalpha(temp[i]))
                temp[i] = '0' + num[temp[i]];
       vec[temp]++;
    }
   for (map<string, int>::const_iterator it = vec.begin(); it != vec.end(); ++it)
   {
       string str = it->first;
       str.insert(3, "-");
       if(it->second > 1)
       {
           flag = false;
           cout << str << " " << it->second << endl;
       }
   }
   if(flag)
     cout <<"No duplicates."<<endl;
    return 0;
}
比较水的一个题,无解的时候需要输出
No duplicates.
一开始没有注意 WA了一次

转载于:https://my.oschina.net/u/196018/blog/383769

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值