pku oj 1002 487-3279

来源:互联网 发布:不用网络的单机跳棋 编辑:程序博客网 时间:2024/04/28 18:59
#include <iostream>#include <string>#include <map>using namespace std;static const int s_table[] = {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 normalize(const string& str){    const int LEN = (int)str.size();    string ret;    for (int i = 0; i < LEN; i++)    {        if (str[i] >= '0' && str[i] <= '9') ret.push_back(str[i]);        else if (str[i] >= 'A' && str[i] <= 'Z') ret.push_back(s_table[str[i]-'A']+'0');    }    ret.insert(3, 1, '-');    return ret;}int main(){    int n;    string line;    map<string, int> statistics;    cin>>n;    for (int i = 0; i < n; i++)    {        cin>>line;        statistics[normalize(line)]++;    }    bool none = true;    for (map<string, int>::iterator it = statistics.begin(); it != statistics.end(); it++)    {        if (it->second > 1)        {            cout<<it->first<<" "<<it->second<<endl;            none = false;        }    }    if (none) cout<<"No duplicates."<<endl;    return 0;}
    这题相对还是比较简单的,用了STL的map就省了很多事情。把所有的号码都转成标准的形式,作为关键字存到map里,最后再扫描一下map输出。内存和速度不太好,不过简单易懂能用就行了。