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 |
总是WA请帮忙看一下,谢谢。#include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <string.h> typedef struct _node { char data[9]; short repeat; struct _node *left; struct _node *right; } Node; int flag = 0; void insert(Node** list, char str[], int len) { int cmp; if(!(*list)) { *list = (Node*)malloc(sizeof(Node)); strncpy((*list)->data, str, len); (*list)->repeat = 1; (*list)->left = (*list)->right = NULL; } else { cmp = strncmp(str, (*list)->data, len); if(cmp == 0) { (*list)->repeat++; flag = 1; return; } else { cmp < 0 ? insert(&((*list)->left), str, len) : insert(&((*list)->right), str, len); } } } void inOrder(Node *t) { if(t) { inOrder(t->left); if(t->repeat > 1) { printf("%s %d\n", t->data, t->repeat); } inOrder(t->right); } } int main() { char t[20]; char c; int count, i, j; Node * head = NULL; scanf("%d%*c", &count); for(i = 0; i < count; i++) { j = 0; while((c=getchar()) != '\n') { if(j == 3) t[j++] = '-'; if(isdigit(c)) { t[j++] = c; } else if(isupper(c)) { if(c == 'S' || c == 'V' || c == 'Y') { t[j++] = (c - 'A') / 3 + '1'; } else { t[j++] = (c - 'A') / 3 + '2'; } } } t[j] = '\0'; insert(&head, t, strlen(t)); } if(!flag) { printf("No duplicates.\n"); } else { inOrder(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