Note that there are some explanatory texts on larger screens.

plurals
  1. POcomparing bits (one position at a time)
    primarykey
    data
    text
    <p><img src="https://i.stack.imgur.com/a8L5M.png" alt="alt text"></p> <p>Initially I have user input decimal numbers (0 - 15), and I will turn that into binary numbers. Say these numbers are written into a text file, as shown in the picture. These numbers are arranged by the numbers of 1's. The dash - is used to separate different groups of 1.</p> <p>I have to read this file, and compare strings of one group with the all the strings in the group below, i.e., Group 1 with all the strings in group 2, and group 2 - group 3.</p> <p>The deal is that, only one column of 0 / 1 difference is allowed, and that column is replaced by letter t. If more than one column of difference is encountered, write none. So say group 2, 0001 with group 3, 0011, only the second column is different. however, 0010 and 0101 are two columns of difference.</p> <p>The result will be written into another file.....</p> <p>At the moment, when I am reading these strings, I am using vector <em>string</em>. I came across bitset. What is important is that I have to access the character one at a time, meaning I have break the vector <em>string</em> into vector <em>char</em>. But it seems like there could be easier way to do it.</p> <p>I even thought about a hash table - linked-list. Having group 1 assigned to H[0]. Each comparison is done as H[current-group] with H[current_group+1]. But beyond the first comparison (comparing 1's and 0's), the comparison beyond that will not work under this hash-linked way. So I gave up on that.</p> <pre><code>#include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;vector&gt; #include &lt;string&gt; #include &lt;algorithm&gt; #include &lt;iterator&gt; using namespace std; int main() { ifstream inFile("a.txt"); vector&lt;string&gt; svec; copy(istream_iterator&lt;string&gt;(inFile), istream_iterator&lt;string&gt;(), back_inserter(svec)); copy(svec.begin(), svec.end(), ostream_iterator&lt;string&gt;(cout,"\n")); for(int i = 0; i &lt; svec.size(); i++) { cout &lt;&lt; svec[i] &lt;&lt; " "; } inFile.close(); return 0; } </code></pre> <p>This is the sample code of writing it into a file....but like I said, the whole deal of vector seems impractical in my case....</p> <p>Any help is appreciated. thanks</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.
 

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