UVA - 755 487--3279

UVA - 755 487–3279

题目大意:题目给定 n 串字符串,包括0-9,A-Z 和 ‘-’ ,求其对应的号码,并按字典序从小到大排序,输出出现次数大于等于2的号码,格式为xxx-xxxx。如果没有结果 No duplicates.
解题思路: 我是字符串读入然后再将所有的转换成xxx-xxxx的字符串形式,然后用qsort排序,然后累加重复的号码输出即可

#include <cstdio>
#include <cstring>
#include <algorithm>
int cmp ( const void  *_a, const void *_b) {
    char *a = (char*)_a;
    char *b = (char*)_b;
    return strcmp(a,b);
}
int main() {
    int N;
    int flag;
    int t;
    int M;
    int ssss = 1;
    int bb[] = {2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 0, 7, 7, 8, 8, 8, 9, 9, 9, 0};
    char a[10000][100];
    char b[10000][10];
    int c[10000];
    scanf("%d", &N);
    getchar();
    while (N--) {
        memset(a, 0, sizeof(a));
        memset(b, 0, sizeof(b));
        memset(c, 0, sizeof(c));
        if (ssss != 1) printf("\n");
        ssss++;
        scanf("%d", &M);
        for (int i = 0; i < M; i++) {
            t = 7;
            scanf("%s", a[i]);
            for (int j = strlen(a[i]); j >= 0; j--) {
                int sssss = a[i][j] - 'A';
                if (t == 3) t--;
                b[i][3] = '-';
                if ( a[i][j] >= 'A' && a[i][j] <= 'Z') {
                    b[i][t] = '0' + bb[sssss];
                    t--;
                }else       
                    if (a[i][j] >= '0' && a[i][j] <= '9') { 
                        b[i][t] = a[i][j];
                        t--;
                    }
            }   
            if (t < 2)
            t++;
            if ( t >= 0)
                for (int j = 0; j < t; j++) {
                    if ( j == 3) {
                        j++;
                        t++;
                    }
                    b[i][j] = '0';
                }
        }
        qsort (b, M, 10, cmp);
        int ttttt = 1;
            flag = 0;
        for (int i = 0; i < M; i++) {
            if (strcmp(b[i], b[i+1]) == 0 ) 
                ttttt++;
            else 
                if (ttttt > 1 ) {
                    flag = 1;
                    printf("%s %d\n", b[i], ttttt);
                    ttttt = 1;
                }
        }
            if (!flag)
                printf("No duplicates.\n");


    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值