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:

 <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>


1 "This is some title"
3 "Another title"
2 "And one more"
1 COmment
1 Another
3 Great
2 Awesome
3 Lucky
2 Stanley


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!

Edited by Josh_3

6 Days
Discussion Span
Last Post by thines01

You need a list of structures that are arranged by title, with a sub-structure of the comments associated. Then you can use either an array of structures (or in C++ a map ordered by title) or linked list. Make an effort to solve this and then post your code here if you want more substantial help.


What compiler are you using and what is considered "off-limits"?
You need to "group" your records by the ID.
If your grouping container does not keep the same order as the file, you will need to index the records when they are selected.

1) Test for the presence of quotes to determine the actual title
2) Reverse order the comments, join them together separated by a space.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.