O
O
Orangeek2018-05-23 22:48:28
C++ / C#
Orangeek, 2018-05-23 22:48:28

Find the most frequently occurring word in the text. Entering words into a dynamic array. How to do without map?

Task: Find the most frequent word in the text, while counting, ignoring the words from the first line.
There is an idea that you need to put the words from the first line into an array, so that, for example, words[n][i] is the n-th word of the line. Next, put all the other words that do not match any of the first array into the second same array, and already in it calculate the most frequently occurring word.
Honestly, I will be glad to any ideas and code, because I have a hard idea how to do it without map and in pure C.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Rsa97, 2018-05-23
@Rsa97

how to do it without map and in pure C

This is obvious, you need to write your own implementation of map in pure C.
And according to the algorithm, it may be faster to first find the frequencies of all words, and only then exclude the words from the first line.

V
Vitaly, 2018-05-23
@vt4a2h

Find/make an associative container. I think there are plenty of implementations of binary search trees in C. You can also make a simple hash table on your knee, probably even easier. It's just that with the usual linear search in the array, the program will work for you for a very long time.
If a real project, and not just a task for self-development, then definitely look for ready-made implementations.

R
res2001, 2018-05-24
@res2001

Use a hash table, such as khash from klib , and there are other structures as well. The library is written in C.

D
Derevianko Alexander, 2018-05-31
@dio4

Pay attention to the function char * strstr( const char * string1, const char * string2 );
there
is no need for any complications. Standard C function - described in string.h
Searched substrings will be words from the 1st line and so on.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question