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<string.h> #include<stdlib.h> typedef struct node NODE,*LINK; struct node{ char a[9]; int time; LINK next; }; int n,k; char chang(char c){ if(c<'Q') return (c-'A')/3+2+'0'; else return (c-'A'-1)/3+2+'0'; } LINK build_node(void){ LINK head=NULL,rear=NULL,newnode,t; int i,j; char c,temp[9]={'\0'}; fflush(stdin); for(i=0;i<n;++i){ j=0; while((c=getchar())!='\n'){ if(c!='-'){ if(c>='0'&&c<='9') temp[j++]=c; else temp[j++]=chang(c); } if(j==3) temp[j++]='-'; } if(head!=NULL){ newnode=head; while(newnode!=NULL){ if(strcmp(temp,newnode->a)==0){ ++newnode->time; k=1; break; } else{ newnode=newnode->next; } } if(newnode==NULL){ newnode=(LINK)calloc(1,sizeof(NODE)); strcpy(newnode->a,temp); t=head; while(t!=NULL&&(strcmp(t->a,newnode->a)<0)){ rear=t; t=t->next; } if(t!=NULL){ if(t==head){ newnode->next=head; head=newnode; } else{ newnode->next=t; rear->next=newnode; } }else{ rear->next=newnode; } } }else{ head=(LINK)calloc(1,sizeof(NODE)); strcpy(head->a,temp); } } return head; } void printf_node(LINK t){ if(t!=NULL){ if(t->time>0) printf("%s %d\n",t->a,t->time+1); printf_node(t->next); } } void free_node(LINK head){ if(head!=NULL){ free(head->next); free(head); } } int main(){ LINK head,t; scanf("%d",&n); head=build_node(); if(k==1){ t=head; printf_node(t); }else{ printf("No duplicates"); } free_node(head); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator