POJ 1002 487-3279

/*
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了

你可能感兴趣的:(poj)