Problem p02266 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stack>
using namespace std;

struct TPond {
  int DownPoint;
  int Surface;
};

void ConstructPond(stack<TPond> &PondRow, stack<int> &DownPointRow,
                   int InputCount) {
  TPond Pond;
  Pond.DownPoint = DownPointRow.top();
  Pond.Surface = InputCount - DownPointRow.top();
  //???????±????????????´?????????????±??????????
  //???????±????????????´????????´?????????
  //	cout << Pond.DownPoint << ' ' << Pond.Surface << endl;
  if (PondRow.empty()) {
    PondRow.push(Pond);
    DownPointRow.pop();
  } else {
    //????????´???????±????????????§???????±????????????????????????°?±?list???????????????
    //????????´???????±????????????§???????±????????????????????????°????????´???????±???????????????????
    if (Pond.DownPoint > PondRow.top().DownPoint) {
      PondRow.push(Pond);
      DownPointRow.pop();
    } else {
      while (!PondRow.empty() && Pond.DownPoint < PondRow.top().DownPoint) {
        Pond.Surface += PondRow.top().Surface;
        PondRow.pop();
      }
      PondRow.push(Pond);
      DownPointRow.pop();
    }
  }
  return;
}

void Output(stack<TPond> PondRow) {
  stack<TPond> DummyPondRow;
  int Count = 0;
  //?????¢???????±???????
  int SumOfSurface = 0;
  while (!PondRow.empty()) {
    SumOfSurface += PondRow.top().Surface;
    DummyPondRow.push(PondRow.top());
    PondRow.pop();
    Count += 1;
  }

  //?????¢?????¨??°???????????????
  cout << SumOfSurface << endl << Count << ' ';
  //?????????????????¢??????????????????
  for (int i = 0; i < Count - 1; i++) {
    cout << DummyPondRow.top().Surface << ' ';
    DummyPondRow.pop();
  }
  cout << DummyPondRow.top().Surface << endl;
  return;
}

int main() {
  //?±?(????????????????????°??¨??¢???????????±?????????)????????????list???????????????
  stack<TPond> PondRow;
  //????????????????????°????????????stack???????????????
  stack<int> DownPointRow;
  //????????????????????°???????????????????????????????????°???????????????
  int InputCount = 0;
  while (true) {
    //??????????????????????????\\???????????\\?????????
    char Input;
    cin >> Input;
    if (cin.good() == false) {
      break;
    }
    InputCount += 1;
    //???????????\\???????????????DownPointRow???????????????
    if (Input == '\\\\') {
      DownPointRow.push(InputCount);
    } //???????????\\????????????????????´?????????????????????????±?????§??????????
    if (Input == '/' && !DownPointRow.empty()) {
      ConstructPond(PondRow, DownPointRow, InputCount);
    }
    //		cout << PondRow.empty() << endl;
    //		cout << DownPointRow.empty() << endl;
  }
  //????????????????????¨
  //	cout << InputCount;
  //	cout << DownPointRow.empty();
  //	cout << PondRow.empty();
  //	cout << PondRow.top().DownPoint << ' ' << PondRow.top().Surface << endl;

  //?±?list????????¨???????±?????????¢?????¨?±??????°??¨???????????????????????¢??????????????????
  if (PondRow.empty()) {
    cout << 0 << endl << 0 << endl;
  } else {
    Output(PondRow);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stack>
using namespace std;

struct TPond {
  int DownPoint;
  int Surface;
};

void ConstructPond(stack<TPond> &PondRow, stack<int> &DownPointRow,
                   int InputCount) {
  TPond Pond;
  Pond.DownPoint = DownPointRow.top();
  Pond.Surface = InputCount - DownPointRow.top();
  //???????±????????????´?????????????±??????????
  //???????±????????????´????????´?????????
  //	cout << Pond.DownPoint << ' ' << Pond.Surface << endl;
  if (PondRow.empty()) {
    PondRow.push(Pond);
    DownPointRow.pop();
  } else {
    //????????´???????±????????????§???????±????????????????????????°?±?list???????????????
    //????????´???????±????????????§???????±????????????????????????°????????´???????±???????????????????
    if (Pond.DownPoint > PondRow.top().DownPoint) {
      PondRow.push(Pond);
      DownPointRow.pop();
    } else {
      while (!PondRow.empty() && Pond.DownPoint < PondRow.top().DownPoint) {
        Pond.Surface += PondRow.top().Surface;
        PondRow.pop();
      }
      PondRow.push(Pond);
      DownPointRow.pop();
    }
  }
  return;
}

void Output(stack<TPond> PondRow) {
  stack<TPond> DummyPondRow;
  int Count = 0;
  //?????¢???????±???????
  int SumOfSurface = 0;
  while (!PondRow.empty()) {
    SumOfSurface += PondRow.top().Surface;
    DummyPondRow.push(PondRow.top());
    PondRow.pop();
    Count += 1;
  }
  //?????¢?????¨??°???????????????
  cout << SumOfSurface << endl << Count << ' ';
  //?????????????????¢??????????????????
  for (int i = 0; i < Count - 1; i++) {
    cout << DummyPondRow.top().Surface << ' ';
    DummyPondRow.pop();
  }
  cout << DummyPondRow.top().Surface << endl;
}

int main() {
  //?±?(????????????????????°??¨??¢???????????±?????????)????????????list???????????????
  stack<TPond> PondRow;
  //????????????????????°????????????stack???????????????
  stack<int> DownPointRow;
  //????????????????????°???????????????????????????????????°???????????????
  int InputCount = 0;
  while (true) {
    //??????????????????????????\\???????????\\?????????
    char Input;
    cin >> Input;
    if (cin.good() == false) {
      break;
    }
    InputCount += 1;
    //???????????\\???????????????DownPointRow???????????????
    if (Input == '\\\\') {
      DownPointRow.push(InputCount);
    } //???????????\\????????????????????´?????????????????????????±?????§??????????
    if (Input == '/' && !DownPointRow.empty()) {
      ConstructPond(PondRow, DownPointRow, InputCount);
    }
    //		cout << PondRow.empty() << endl;
    //		cout << DownPointRow.empty() << endl;
  }
  //????????????????????¨
  //	cout << InputCount;
  //	cout << DownPointRow.empty();
  //	cout << PondRow.empty();
  //	cout << PondRow.top().DownPoint << ' ' << PondRow.top().Surface << endl;

  //?±?list????????¨???????±?????????¢?????¨?±??????°??¨???????????????????????¢??????????????????
  Output(PondRow);
  return 0;
}