Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Firstly take care of data structures - it's a good practice. As you see, there are may be these structures:</p> <pre class="lang-cpp prettyprint-override"><code>map&lt;string, int&gt; answers; struct question { int id; string text; int answer; } list&lt;question&gt; questions; </code></pre> <p>As you see it's better to place answers in file before questions. Why? Because you can write a program by this way:</p> <ol> <li>Parse answers and fill <code>answers</code> map.</li> <li>Parse question and fill <code>questions</code>. Just put an answer's number in <code>answers[answer_string]</code> to get a corresponding answer's number.</li> </ol> <p>Now you have everything to create an algorithm. Lets see how does generally work a simple parser for this case:</p> <ol> <li>Skip all spaces.</li> <li>Read a symbol <code>s</code>. If <code>s == 'W'</code> then read an answer's number. Else if <code>s == 'Q'</code> read a question's number.</li> <li>If <code>s == '"'</code> read a question's string until next '"'.</li> <li>If <code>s == '['</code> read a question's answer string until ']'.</li> <li>If <code>s == '&lt;'</code> read an answer's string until '>'.</li> </ol> <p>Just use these rules and you will get a recursive parsing algorithm. Also it would be good to read about <a href="http://en.wikipedia.org/wiki/Recursive_descent_parser" rel="nofollow">recursive descent parsers</a> for details.</p> <p>That's all! You have data structures and an algorithm. Now you can write some code.</p> <p>And why not to use a number for question's answer instead of string to reduce duplications? :-) </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload