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了一次

你可能感兴趣的:(OJ百练1002 487-3279)