POJ: 1002 487-3279

POJ: 1002 487-3279

Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 324245 Accepted: 57280

时间和内存要求都不是特别严格,练手小题。

Sample Input

12
4873279
ITS-EASY
888-4567
3-10-10-10
888-GLOP
TUT-GLOP
967-11-11
310-GINO
F101010
888-1200
-4-8-7-3-2-7-9-
487-3279

Sample Output

310-1010 2
487-3279 4
888-4567 3

Accepted Source Code

5052K 1079MS

//  487-3279
/*  Time Limit: 2000MS		        Memory Limit: 65536K
    Total Submissions: 324226		Accepted: 57277        */
    
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#define dbg 0

using namespace std;
map<char, char> m1;
map<string, int> m2;
int main() {
    m1['A'] = '2';
    m1['B'] = '2';
    m1['C'] = '2';
    m1['D'] = '3';
    m1['E'] = '3';
    m1['F'] = '3';
    m1['G'] = '4';
    m1['H'] = '4';
    m1['I'] = '4';
    m1['J'] = '5';
    m1['K'] = '5';
    m1['L'] = '5';
    m1['M'] = '6';
    m1['N'] = '6';
    m1['O'] = '6';
    m1['P'] = '7';
    m1['R'] = '7';
    m1['S'] = '7';
    m1['T'] = '8';
    m1['U'] = '8';
    m1['V'] = '8';
    m1['W'] = '9';
    m1['X'] = '9';
    m1['Y'] = '9';

    char str[1024];

#if dbg
    printf("Hello.%d\n", 101);
    FILE* fp;
    fopen_s(&fp, "poj/build/p1002.si", "r");
    if (fp == NULL) {
        printf("ERROR LOADING FILE.\n");
        return -1;
    }

    int cnt;
    fgets(str, 1024, fp);
    sscanf(str, "%d", &cnt);
    // fscanf(fp, "%d", &cnt);
#else
    int cnt;
    gets(str);
    sscanf(str, "%d", &cnt);
#endif

    char res[9];
    int eff;  // 有效输出
    for (int i = 0; i < cnt; i++) {
#if dbg
        printf("%s", fgets(str, 1024, fp));
#else
        gets(str);
#endif
        eff = 0;
        res[3] = '-';
        res[8] = '\0';
        if (strlen(str) >= 7) {
            for (int j = 0; j < strlen(str); j++) {
                char c = str[j];
                if (eff == 3) {
                    // printf("-");
                    eff = 4;
                }
                if (c >= 'A' && c <= 'Z') {
                    // printf("%d", m1[str[j]]);
                    res[eff] = m1[c];
                    eff++;
                } else if (c >= '0' && c <= '9') {
                    // printf("%c", str[j]);
                    res[eff] = c;
                    eff++;
                }
            }
        }
        m2[res] = m2[res] + 1;
#if dbg
        printf("%s\n", res);
        printf("%d\n", m2[res]);
#endif
    map<string, int>::iterator it;
    int effcnt = 0;
    for (it = m2.begin(); it != m2.end(); it++) {
        string s = it->first;
        s = s.substr(0, 8);
#if 0
        printf("%s, %d\n", s.data(), it->second);
#endif
        if (s.size() == 8 && it->second > 1) {
            effcnt++;
            printf("%s %d\n", s.data(), it->second);
        }
    }
    if (effcnt == 0) {
        printf("No duplicates.\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值