poj1002 487-3279

题目大意:就是给你一些符号和大写字母对应的数字,要求全部转化成电话号码XXX-XXXX的形式,其中X只能是数字,这些字符串的长度不等,里面会有一些‘-’,最后要求是找出出现次数>1的电话号码,输出号码和重复出现的次数,如果没有重复的号码,就输出:“No duplicates.”
WA的同学注意“No duplicates.”不要漏掉“.”。
TLE的同学注意把cin和cout改成scanf和printf。
在选择G++和C++后结果可能会有些不同,如果G++过不了换C++试试,如果C++过不了换G++试试。

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int n;
int a[200000];
int ans[200000];
int vis[10000000];
int main()
{
    scanf("%d",&n);
    int tot = 0;
    for(int i = 1; i <= n; i ++)
    {
        int len = 1;char s;int h = 0;
        while(len <= 7)
        {
            while ((s = getchar()) != '\n')
            if(s!='-')
            {
                if(s-'0' < 10)
                h += ((s-'0')*pow(10,(7-len)));
                else if(s == 'A'||s == 'B'||s == 'C')
                {
                    h +=(2*pow(10,7-len));
                }
                else if(s == 'D'||s == 'E'||s == 'F')
                {
                    h +=(3*pow(10,7-len));
                }
                else if(s == 'G'||s == 'H'||s == 'I')
                {
                    h +=(4*pow(10,7-len));
                }
                else if(s == 'J'||s == 'K'||s == 'L')
                {
                    h +=(5*pow(10,7-len));
                }
                else if(s == 'M'||s == 'N'||s == 'O')
                {
                    h +=(6*pow(10,7-len));
                }
                else if(s == 'P'||s == 'R'||s == 'S')
                {
                    h +=(7*pow(10,7-len));
                }
                else if(s == 'T'||s == 'U'||s == 'V')
                {
                    h +=(8*pow(10,7-len));
                }
                else if(s == 'W'||s == 'X'||s == 'Y')
                {
                    h +=(9*pow(10,7-len));
                }
                len++;
            }
        }
        vis[h] ++;
        a[i] = h;
    }
    bool flag = 0;
    for(int i = 1; i <= n; i ++)
    {
        if(vis[a[i]]>1)
        {
            flag = 1;
            ans[++tot] = a[i];
        }
    }
    if(!flag)
    {
        puts("No duplicates.");
        return 0;
    }
    sort(ans+1,ans+tot+1);
    for(int i = 1; i <= tot ; i ++)
    {
        if(ans[i] != ans[i+1])
        {
            printf("%d%d",ans[i]/1000000,(ans[i]/100000)%10);
            printf("%d",(ans[i]/10000)%10);
            cout <<"-";
            printf("%d%d",(ans[i]/1000)%10,(ans[i]/100)%10);
            printf("%d%d",(ans[i]/10)%10,ans[i]%10);
            cout <<" ";
            cout <<vis[ans[i]]<<endl;
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值