I am learning to code and found interesting task, but i do not know where to start in solving it. So i have a file with some titles and comments which need to be placed under the right title. So the first line of the input contains a number N which determines the quantity of the titles. Each row starts with a unique article id (integer), followed by the title in quotation marks. After there is no more titles, comments are given. At the beginning there is Title ID and comment (one word), but comments may recur for the same ID. so here is a structure of a file:
<N>
<ID1> "<Title1>"
...
<IDN> "<TitleN>"
<ID1> <Comment1>
...
<IDK> <CommentK>
Now in the output file each Title has two lines - first for the title and second one for comments. Titles must be in ascending order. And comments should be in reverse order (newest comments in the beginning) Structure of output file:
<Title1> <Comment11> ... < CommentK1>
...
<TitleN> <Comment1N> ... < CommentLN>
Example:
input:
3
1 "This is some title"
3 "Another title"
2 "And one more"
1 COmment
1 Another
3 Great
2 Awesome
3 Lucky
2 Stanley
output:
This is some title
Another COmment
And one more
Stanley Awesome
Another Title
Lucky Great
I do not now where to begin with.. Should I use arrays to save the data in memory and then try to sort it in the right pattern?Or is it better to load the text file into a data structure; in this case a linked list? Maybe someone can guide me in the right direction how to accomplish this task. (I do not ask to code it for me, just guide me or give some algorithm, it would be highly appreciated). Thanks!