zoukankan      html  css  js  c++  java
  • POJ 1002 4873279

    /*
    POJ 1002 487-3279
    */
    # include <stdio.h>
    # include <stdlib.h>
    # include <ctype.h>

    typedef struct TeleNum
    {
    int num;
    int rpt;
    struct TeleNum *next;
    } tel;

    const int h[] = {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
    };
    int main()
    {
    char ch;
    int tot, n, cnt;
    tel *head, *p, *q, *t;

    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);

    while (scanf("%d", &tot) != EOF)
    {
    getchar();
    head = NULL;
    while (tot > 0)
    {
    n = 0;
    p = (tel *)malloc(sizeof(tel));

    while ((ch=getchar()) != '\n')
    if (isalpha(ch) && ch!= 'Q' && ch!='Z')
    {
    n += h[ch-'A'];
    n *= 10;
    }
    else if (ch>='0' && ch<='9')
    {
    n += ch-'0';
    n *= 10;
    }
    n /= 10;

    p->num = n;
    p->rpt = 1;
    p->next = NULL;

    if (head != NULL)
    {
    q = head;
    while (p->num > q->num)
    {
    t = q;
    q = q->next;
    if (q == NULL) break;
    }
    if (q!=NULL && p->num==q->num)
    {
    free(p);
    ++(q->rpt);
    }
    else
    {
    p->next = q;
    if (q == head) head = p;
    else t->next = p;
    }
    }
    else head = p;

    --tot;
    }
    cnt = 0;
    q = head;
    while (q != NULL)
    {
    if (q->rpt > 1)
    {
    printf("%03d-%04d %d\n", (q->num)/10000, (q->num)%10000, q->rpt);
    ++cnt;
    }
    q = q->next;
    }
    if (cnt == 0) printf("No duplicates.\n");

    }

    return 0;
    }


    TLE了

  • 相关阅读:
    Mac终端编写c语言程序方法
    X-code最常用快捷键
    类方法和实例方法区别
    一、SQL语句中的增、删、查、改
    从零开始,学习web前端之HTML基础
    图片 自适应 容器大小
    Java第二天 数据类型
    Java 第一天
    javascript的基础知识
    JavaScript(一)
  • 原文地址:https://www.cnblogs.com/JMDWQ/p/2361682.html
Copyright © 2011-2022 走看看