All pastes #732926 Raw Edit

Someone

public text v1 · immutable
·published 2007-10-11 12:01 UTC
rendered paste body
#include <iostream>
#include <string>
#include <list>
using namespace std;

int main()
{
  for(int i = 0; i < 10; ++i)
  {
    string s;
    int maxDepth = 0, maxCount = 0, count = 0, n, depth = 0;
    list<bool> status;
    cin >> n >> s;
    for(int j = 0; j < s.size(); ++j)
    {
      if(s[j] == '0')
      {
        if(depth == 0)
          break;
        if(depth > maxDepth)
        {
          maxDepth = depth;
          maxCount = count;
        }
        while(depth > 0 && status.back())
        {
          --depth;
          status.pop_back();
        }
        status.back() = true;
      }
      else
      {
        ++count;
        ++depth;
        status.push_back(false);
      }
    }
    cout << maxCount << endl;
  }
}