Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
晕啊 怎么老超时呢#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> typedef struct node { char s[10]; int times; struct node *link; }NODE; int main() { int n,i,ch; NODE *phead,*p0,*p1,*ptmp; phead=(NODE*)malloc(sizeof(NODE)); p0=(NODE*)malloc(sizeof(NODE)); if(phead==NULL || p0==NULL){ puts("memory not enough!"); exit(1); } phead->link = p0; scanf("%d",&n); getchar(); while(n--){ p1 = p0; i = 0; while((ch=getchar()) != '\n'){ if(i == 3) p1->s[i++] = '-'; if(isdigit(ch)) p1->s[i++] = ch; else if(isalpha(ch)) if(ch < 'Q') p1->s[i++] = (ch-59)/3 + '0'; else p1->s[i++] = (ch-60)/3 + '0'; } p1->s[i] = '\0'; p1->times = 1; if((p0=(NODE*)malloc(sizeof(NODE))) == NULL){ puts("memory not enough!"); exit(1); } p1->link = p0; } p1->link = NULL; p1 = phead->link->link; p0 = phead; phead->link->link = NULL; while(p1){ while(p0->link && (i=strcmp(p1->s,p0->link->s)) > 0) p0 = p0->link; if(i == 0){ p0->link->times++; p1 = p1->link; p0 = phead; continue; } ptmp = p1; p1 = p1->link; ptmp->link = p0->link; p0->link = ptmp; p0 = phead; } for(p0=phead->link; p0!=NULL; p0=p0->link) if(p0->times > 1) printf("%s %d\n", p0->s, p0->times),n=0; if(n) printf("No duplicates.\n"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator