Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't understand your code snippet -- it looks like all it does is read in the input file into a vector of strings, which will then contain each whitespace-delimited word in a separate string, then write it back out in 2 different ways (once with words separated by <code>\n</code>, once with them separated by spaces).</p> <p>It seems the main problem you're having is with reading and interpreting the file itself, as opposed to doing the necessary calculations -- right? That's what I hope this answer will help you with.</p> <p>I think the line structure of the file is important -- right? In that case you would be better off using the <a href="http://www.cplusplus.com/reference/string/getline/" rel="nofollow">global <code>getline()</code> function in the <code>&lt;string&gt;</code> header</a>, which reads an entire line (rather than a whitespace-delimited word) into a string. (Admittedly that function is pretty well-hidden!) Also you don't actually need to read all the lines into a vector, and then process them -- it's more efficient and actually easier to distill them down to numbers or bitsets as you go:</p> <pre><code>vector&lt;unsigned&gt; last, curr; // An unsigned can comfortably hold 0-15 ifstream inf("a.txt"); while (true) { string line; getline(inf, line); // This is the group header: ignore it while (getline(inf, line)) { if (line == "-") { break; } // This line contains a binary string: turn it into a number // We ignore all characters that are not binary digits unsigned val = 0; for (int i = 0; i &lt; line.size(); ++i) { if (line[i] == '0' || line[i] == '1') { val = (val &lt;&lt; 1) + line[i] - '0'; } } curr.push_back(val); } // Either we reached EOF, or we saw a "-". Either way, compare // the last 2 groups. compare_them_somehow(curr, last); // Not doing everything for you ;) last = curr; // Using swap() would be more efficient, but who cares curr.clear(); if (inf) { break; // Either the disk exploded, or we reached EOF, so we're done. } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. 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