Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // uloha4-2.c -- Daniel Kavuliak, 21.9.2018 14:27
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct Node
- {
- struct Node* children[26];
- }NODE;
- int findPrefix(NODE** current, char* word, int n)
- {
- int i = word[0] - 'A';
- if (word[0] == '\0')
- return n;
- if ((*current)->children[i] == NULL)
- {
- (*current)->children[i] = (NODE*)calloc(1, sizeof(NODE));
- return findPrefix(&((*current)->children[i]), word + 1, n);
- }
- else
- return findPrefix(&((*current)->children[i]), word + 1, n + 1);
- }
- int main()
- {
- // sem napis svoje riesenie
- int longest = 0, tmp;
- char buf[50];
- NODE* root = (NODE*)calloc(1, sizeof(NODE));
- while (scanf("%s", buf) > 0)
- {
- tmp = findPrefix(&root, buf, 0);
- if (longest < tmp)
- longest = tmp;
- }
- printf("%d\n", longest);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement