JOJ1490:487-3279

传送门:http://acm.jlu.edu.cn/joj/showproblem.php?pid=1490

思路:就是把所有的字符串转换成XXX-XXXX的格式,统计个数大于1的字符串,并按字典序输出,建议用map做,熟悉一下map的操作。

代码:

#include <cstdio>
#include <cstring>
#include <map>
#include <iostream>
using namespace std;

char change(char x)
{
    if (x == 'A' || x == 'B' || x == 'C')
        return '2';
    if (x == 'D' || x == 'E' || x == 'F')
        return '3';
    if (x == 'G' || x == 'H' || x == 'I')
        return '4';
    if (x == 'J' || x == 'K' || x == 'L')
        return '5';
    if (x == 'M' || x == 'N' || x == 'O')
        return '6';
    if (x == 'P' || x == 'R' || x == 'S')
        return '7';
    if (x == 'T' || x == 'U' || x == 'V')
        return '8';
    if (x == 'W' || x == 'X' || x == 'Y')
        return '9';
    return x;
}

int main()
{
    int n;
    while (scanf("%d", &n) != EOF)
    {
        map<string, int> mapstr;
        for (int i = 0; i < n; ++i)
        {
            char str1[100], str2[100];
            cin >> str1;
            int cnt = 0;
            for (int l = 0; str1[l]; ++l)
            {
                if (str1[l] == '-') continue;
                str2[cnt++] = change(str1[l]);
                if (cnt == 3)
                    str2[cnt++] = '-';
            }
            str2[cnt] = '\0';
            mapstr[str2]++;
        }
        map<string, int> :: iterator iter;
        bool flag = false;
        for (iter = mapstr.begin(); iter != mapstr.end(); iter++)
        {
            if (iter -> second != 1)
            {
                flag = true;
                cout << iter -> first << " " << iter -> second << endl;
            }
        }
        if (!flag)
        {
            cout << "No duplicates." << endl;
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值