poj1002 487-3279 解题报告

本文介绍了一种通过将特定格式的电话号码转换为整数并利用快速排序进行重复号码判断的方法。该方法通过简单的字符串处理,实现了对电话号码的有效判重。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

分析:简单的字符串处理然后判重,一开始sb了,还在想用什么数据结构,其实只要用快排就行

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char st[100];
int a[100010];
int main()
{
    bool fff;
    int n,tot,ii,sum,i,num,x,len;
    scanf("%d",&n);
    tot = 0;
    for (ii = 1; ii <= n; ii++)
    {
        scanf("%s",st); len = strlen(st);
        sum = 0;
        for (i = 0; i < len; i++)
        {
            if (st[i] == '-' || st[i] == 'Q' || st[i] == 'Z') continue;
            if (st[i] >= '0' && st[i] <= '9') x = st[i] - '0';
            else
            {
                switch (st[i])
                {
                    case 'A':case 'B':case 'C': x = 2; break;
                    case 'D':case 'E':case 'F': x = 3; break;
                    case 'G':case 'H':case 'I': x = 4; break;
                    case 'J':case 'K':case 'L': x = 5; break;
                    case 'M':case 'N':case 'O': x = 6; break;
                    case 'P':case 'R':case 'S': x = 7; break;
                    case 'T':case 'U':case 'V': x = 8; break;
                    case 'W':case 'X':case 'Y': x = 9; break;
                }
            }
            sum = sum * 10 + x;
        }
        a[++tot] = sum;
    }
    sort(a+1,a+tot+1);
    a[tot+1] = 99999999;
    fff = true;
    i = 0;
    while (i < tot)
    {
        i++; num = 1;
        while (a[i] == a[i+1])
        {
            fff = false;
            num++;
            i++;
        }
        if (num > 1)
        {
            printf("%03d-%04d %d\n",a[i]/10000,a[i]%10000,num);//学习别人的格式输出
        }
    }
    if (fff == true) printf("No duplicates.\n");
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值