daily pastebin goal
37%
SHARE
TWEET

kopkpok

a guest Oct 18th, 2018 70 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. // uloha4-2.c -- Daniel Kavuliak, 21.9.2018 14:27
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. typedef struct Node
  7. {
  8.   struct Node* children[26];
  9. }NODE;
  10.  
  11. int findPrefix(NODE** current, char* word, int n)
  12. {
  13.   int i = word[0] - 'A';
  14.  
  15.   if (word[0] == '\0')
  16.     return n;
  17.  
  18.   if ((*current)->children[i] == NULL)
  19.   {
  20.     (*current)->children[i] = (NODE*)calloc(1, sizeof(NODE));
  21.     return findPrefix(&((*current)->children[i]), word + 1, n);
  22.   }
  23.   else
  24.     return findPrefix(&((*current)->children[i]), word + 1, n + 1);
  25. }
  26.  
  27. int main()
  28. {
  29.   // sem napis svoje riesenie
  30.   int longest = 0, tmp;
  31.   char buf[50];
  32.   NODE* root = (NODE*)calloc(1, sizeof(NODE));
  33.  
  34.   while (scanf("%s", buf) > 0)
  35.   {
  36.     tmp = findPrefix(&root, buf, 0);
  37.     if (longest < tmp)
  38.       longest = tmp;
  39.   }
  40.  
  41.   printf("%d\n", longest);
  42.  
  43.   return 0;
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top