Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How about:</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;vector&gt; #include &lt;utility&gt; template&lt;typename F, typename S&gt; std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const std::pair&lt;F, S&gt;&amp; t) { return os &lt;&lt; '(' &lt;&lt; t.first &lt;&lt; ',' &lt;&lt; t.second &lt;&lt; ')'; } template&lt;typename T&gt; std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const std::vector&lt;T&gt;&amp; vec) { for (auto&amp; el : vec) { os &lt;&lt; el &lt;&lt; ' '; } return os; } int main() { constexpr unsigned int width = 6; constexpr unsigned int height = 3; const unsigned int array[height][width] = { {1,0,0,0,1,0}, {1,1,0,0,1,1}, {1,0,0,0,0,0}, }; typedef std::vector&lt;std::pair&lt;unsigned int, unsigned int&gt;&gt; colonies; colonies left; colonies right; for (unsigned int y = 0; y &lt; height; ++y) { colonies * vector = &amp;left; for (unsigned int x = 0; x &lt; width; ++x) { const unsigned int value = array[y][x]; if (value == 0) { vector = &amp;right; } else { vector-&gt;push_back(std::make_pair(y, x)); } } } std::cout &lt;&lt; "Right: " &lt;&lt; std::endl &lt;&lt; right &lt;&lt; std::endl; std::cout &lt;&lt; "Left: " &lt;&lt; std::endl &lt;&lt; left &lt;&lt; std::endl; } </code></pre> <p>Output:</p> <pre><code>+ g++-4.8 -std=c++11 -O2 -Wall -pedantic -pthread main.cpp + ./a.out Right: (0,4) (1,4) (1,5) Left: (0,0) (1,0) (1,1) (2,0) </code></pre> <p>You can run it online <a href="http://coliru.stacked-crooked.com/a/f8fedf55dba3f598" rel="nofollow">here</a></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.
 

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