Sauron3

Untitled

Oct 6th, 2014
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. //
  2. //  main.c
  3. //  Uloha 3.2
  4. //
  5. //  Created by Marcel Choma on 3.10.2014.
  6. //  Copyright (c) 2014 Marcel Choma. All rights reserved.
  7. //
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <ctype.h>
  12.  
  13. #define CHILDS_NUMBER 26
  14. #define MAX_WORD_LENGTH 30
  15. #define MAX_WORD 10010
  16.  
  17. typedef struct node
  18. {
  19.     struct node *childs[CHILDS_NUMBER];
  20. }NODE;
  21. int main()
  22. {
  23.     int pom=0, count = 0, max = 0;
  24.     char letterArray[MAX_WORD_LENGTH];
  25.    
  26.     NODE *root, *p_act;
  27.     root = (NODE *) malloc(sizeof(NODE));
  28.  
  29.     while(scanf("%s",letterArray) > 0 )
  30.     {
  31.         p_act = root;
  32.         count = 0;
  33.         char * p = letterArray;
  34.         while (*p != '\0')
  35.         {
  36.             pom = *p - 'A';
  37.             if (p_act->childs[pom] == NULL){
  38.                 p_act->childs[pom] = (NODE *) malloc(sizeof(NODE));
  39.             }else
  40.                 count++;
  41.            
  42.             p_act = p_act->childs[pom];
  43.             p++;
  44.         }
  45.         if (count >= max){
  46.             max = count;
  47.             count = 0;
  48.         }
  49.     }
  50.     printf("%d\n", max);
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment