MLE / SEGF error
<p>I learn by doing, and enjoy using online judge sites to learn.  Right now I am working on 
<a href="http://www.z-training.net/tasks.php?show_task=5000000406" rel="nofollow">http://www.z-training.net/tasks.php?show_task=5000000406</a>.  Some of the test cases pass, but many get MLE/SEGF.  My code is taking a brute force approach.  Is this approach the cause of the MLE/SEGF error?</p>

<pre><code>//z-last char
#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;

int main()
{
string str = "";
string tmp = "";
  string newStr = "";
  unsigned int strSize = 0;
  unsigned int repeat;
  unsigned int i;
  int cnt = 0;

  cin &gt;&gt; str;
  cin &gt;&gt; repeat;

  tmp = str;
  strSize = str.size();

  for (i=1;i&lt;repeat;i++)
  {
    str += tmp;
    strSize += strSize;
  }

  while (strSize &gt; 1)
  {
    cnt = 0;
    newStr = "";
    for (i=1;i&lt;strSize;i=i+2)
    {
      newStr += str[i];
      cnt += 1;
    }
    //cout &lt;&lt; newStr &lt;&lt; endl;
    strSize = cnt;
    str = newStr;

  }

  cout &lt;&lt; newStr &lt;&lt; endl;
  return 0;
}
</code></pre>
