alexjercan/bugnet huggingface dataset:
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

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

struct land {
  char form;
  int height;
};
vector<land> map;
vector<int> tamari;

int calc_slash_index(int back_index) {
  for (int i = back_index + 1; i < map.size(); i++) {
    if (map[i].form == '/' && map[i].height == map[back_index].height) {
      return i;
    }
  }
  return -1;
}

int calc(int back_index, int slash_index) {
  int ret = slash_index - back_index;
  for (int i = back_index + 1; i < slash_index; i++) {
    if (map[i].form == '\\\\') {
      int s = calc_slash_index(i);
      ret += s - i;
    }
  }
  return ret;
}

int main() {
  char c;
  land land_in;
  cin >> land_in.form;
  land_in.height = 0;
  map.push_back(land_in);
  while (cin >> land_in.form) {
    int height_param1;
    int height_param2;
    if (map.back().form == '/') {
      height_param1 = 0;
    } else {
      height_param1 = -1;
    }
    if (land_in.form == '\\\\') {
      height_param2 = 0;
    } else {
      height_param2 = 1;
    }
    land_in.height = map.back().height + height_param1 + height_param2;
    map.push_back(land_in);
  }

  int total = 0;
  for (int i = 0; i < map.size(); i++) {
    if (map[i].form == '\\\\') {
      int slash = calc_slash_index(i);
      if (slash == -1)
        continue;
      int rain = calc(i, slash);
      tamari.push_back(rain);
      total += rain;
      i = slash;
    }
  }
  cout << total << endl;
  cout << tamari.size();
  for (int i = 0; i < tamari.size(); i++) {
    cout << " " << tamari[i];
  }
  cout << endl;
  return 0;
}

Error: 0

Fixed submission:

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

stack<char> form;

int calc() {
  if (form.empty())
    return 0;
  int rain = 0;
  while (form.top() != '/') {
    form.pop();
    if (form.empty())
      return 0;
  }
  form.pop();
  int cnt = 1;
  int rain_tmp = 0;
  while (form.top() != '\\\\') {
    if (form.top() == '/') {
      rain += calc();
    }
    rain_tmp++;
    form.pop();
    if (form.empty())
      return rain;
    cnt++;
  }
  form.pop();
  cnt++;
  rain += rain_tmp + 1;
  for (int i = 0; i < cnt; i++) {
    form.push('_');
  }
  return rain;
}

int main() {
  char c;
  while (cin >> c) {
    form.push(c);
  }
  int total_rain = 0;
  stack<int> tamari;
  int number = 0;
  while (!form.empty()) {
    int rain = calc();
    if (rain) {
      tamari.push(rain);
      total_rain += rain;
      number++;
    }
  }
  cout << total_rain << endl;
  cout << number;
  while (!tamari.empty()) {
    cout << " " << tamari.top();
    tamari.pop();
  }
  cout << endl;

  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int top = 0, c[20000], area[20000][2] = {};

void push(int x) {
  top++;
  c[top] = x;
}

int pop() {
  top--;
  return c[top + 1];
}

int main() {

  int sum = 0, cnt = 0;
  char ch;

  for (int i = 0; cin >> ch; i++) {
    if (ch == '\\\\') {
      push(i);
    } else if (ch == '/' && top > 0) {
      int j = pop(), tmp;
      sum += i - j;
      tmp = i - j;
      while (cnt > 0 && area[cnt][1] > j) {
        tmp += area[cnt][0];
        cnt--;
      }
      cnt++;
      area[cnt][0] = tmp;
      area[cnt][1] = j;
    }
  }

  cout << sum << endl;
  cout << cnt;
  for (int i = 1; i <= cnt; i++)
    cout << " " << area[i][0];
  cout << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int top = 0, c[10000], area[10000][2] = {};

void push(int x) {
  top++;
  c[top] = x;
}

int pop() {
  top--;
  return c[top + 1];
}

int main() {

  int sum = 0, cnt = 0;
  char ch;

  for (int i = 0; cin >> ch; i++) {
    if (ch == '\\\\') {
      push(i);
    } else if (ch == '/' && top > 0) {
      int j = pop(), tmp;
      sum += i - j;
      tmp = i - j;
      while (cnt > 0 && area[cnt][1] > j) {
        tmp += area[cnt][0];
        cnt--;
      }
      cnt++;
      area[cnt][0] = tmp;
      area[cnt][1] = j;
    }
  }

  cout << sum << endl;
  cout << cnt;
  for (int i = 1; i <= cnt; i++)
    cout << " " << area[i][0];
  cout << endl;

  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define N 20005
using namespace std;

int h[N], wh[N];
int nh;
string S;

int main() {
  std::cin >> S;
  int l = S.length();
  h[0] = 0;
  for (int i = 1; i <= l; i++) {
    switch (S[i - 1]) {
    case '\\\\':
      h[i] = h[i - 1] - 1;
      break;
    case '/':
      h[i] = h[i - 1] + 1;
      break;
    case '_':
      h[i] = h[i - 1];
      break;
    }
  }
  int nwh = 0;
  int ans = 0;
  wh[0] = 0;
  for (int i = 1; i <= l; i++) {
    nwh = max(nwh, h[i]);
    wh[i] = nwh;
  }
  nwh = h[l];
  wh[l] = min(wh[l], nwh);
  for (int i = l - 1; i >= 0; i--) {
    nwh = max(nwh, h[i]);
    wh[i] = min(wh[i], nwh);
  }
  vector<int> ws;
  int left = 0;
  int ar2 = 0;
  for (int i = 1; i <= l; i++) {
    ar2 += wh[i] + wh[i - 1] - h[i] - h[i - 1];
    if (wh[left] == h[i]) {
      if (ar2) {
        ws.push_back(ar2 / 2);
      }
      ans += ar2;
      left = i;
      ar2 = 0;
    } else if (wh[i] != wh[left]) {
      left = i;
    }
  }
  cout << ans / 2 << endl;
  if (!ws.empty()) {
    cout << ws.size() << " ";
    rep(i, ws.size() - 1) { cout << ws[i] << " "; }
    cout << ws.back() << endl;
  } else {
    cout << 0 << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define N 20005
using namespace std;

int h[N], wh[N];
int nh;
string S;

int main() {
  std::cin >> S;
  int l = S.length();
  h[0] = 0;
  for (int i = 1; i <= l; i++) {
    switch (S[i - 1]) {
    case '\\\\':
      h[i] = h[i - 1] - 1;
      break;
    case '/':
      h[i] = h[i - 1] + 1;
      break;
    case '_':
      h[i] = h[i - 1];
      break;
    }
  }
  int nwh = 0;
  int ans = 0;
  wh[0] = 0;
  for (int i = 1; i <= l; i++) {
    nwh = max(nwh, h[i]);
    wh[i] = nwh;
  }
  nwh = h[l];
  wh[l] = min(wh[l], nwh);
  for (int i = l - 1; i >= 0; i--) {
    nwh = max(nwh, h[i]);
    wh[i] = min(wh[i], nwh);
  }
  vector<int> ws;
  int left = 0;
  int ar2 = 0;
  for (int i = 1; i <= l; i++) {
    ar2 += wh[i] + wh[i - 1] - h[i] - h[i - 1];
    if (wh[left] == h[i]) {
      if (ar2) {
        ws.push_back(ar2 / 2);
      }
      ans += ar2;
      left = i;
      ar2 = 0;
    } else if (wh[i] != wh[left]) {
      left = i;
    }
  }
  cout << ans / 2 << endl;
  cout << ws.size() << " ";
  rep(i, ws.size() - 1) { cout << ws[i] << " "; }
  if (!ws.empty())
    cout << ws.back() << endl;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

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

char section[20000];
int tot_area = 0;

int main() {
  cin >> section;
  stack<int> S;
  stack<pair<int, int>> S2;

  for (int i = 0; i < strlen(section); i++) {
    if (section[i] == '\\\\') {
      S.push(i);
    }
    if (section[i] == '/' && !S.empty()) {
      int left = S.top();
      S.pop();
      tot_area += i - left;

      int area = i - left;
      while (!S2.empty() && S2.top().first > left) {
        area += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(left, area));
    }
  }

  vector<int> ans;
  int length = S2.size();
  if (length) {
    for (int i = 0; i < length; i++) {
      ans.push_back(S2.top().second);
      S2.pop();
    }

    cout << tot_area << endl << length << ' ';
    for (int i = length - 1; i > 0; i--)
      cout << ans[i] << ' ';

    cout << ans[0] << endl;
  } else
    cout << 0 << endl << 0 << endl;

  //	cin.get();
  //	cin.get();
  return 0;
}

Error: 0

Fixed submission:

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

char section[20000];
int tot_area = 0;

int main() {
  cin >> section;
  stack<int> S;
  stack<pair<int, int>> S2;

  for (int i = 0; i < strlen(section); i++) {
    if (section[i] == '\\\\') {
      S.push(i);
    }
    if (section[i] == '/' && !S.empty()) {
      int left = S.top();
      S.pop();
      tot_area += i - left;

      int area = i - left;
      while (!S2.empty() && S2.top().first > left) {
        area += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(left, area));
    }
  }

  vector<int> ans;
  int length = S2.size();
  for (int i = 0; i < length; i++) {
    ans.push_back(S2.top().second);
    S2.pop();
  }

  cout << tot_area << endl << length << ' ';
  for (int i = length - 1; i > 0; i--)
    cout << ans[i] << ' ';

  cout << ans[0] << endl;

  //	cin.get();
  //	cin.get();
  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

#include "algorithm"
#include "iostream"
#include "stack"
#include "vector"

using namespace std;

struct Mizu {
  int pos, val;
};

int main() {

  stack<int> s;
  stack<Mizu> each;

  char input[20001];
  int ans = 0;

  cin >> input;

  for (int i = 0;; i++) {
    if (input[i] == '\\\\') {
      s.push(i);
    } else if (input[i] == '/') {
      if (!s.empty()) {
        ans += i - s.top();

        Mizu biger;
        biger.pos = s.top();
        biger.val = 0;

        while (!each.empty()) {
          if (each.top().pos < s.top()) {
            break;
          }
          Mizu m;
          m = each.top();
          each.pop();

          biger.pos = m.pos;
          biger.val += m.val;
        }
        biger.val += i - s.top();
        each.push(biger);
        s.pop();
      }
    } else if (input[i] == '_')
      ;
    else
      break;
  }

  cout << ans << endl;

  vector<int> v;

  while (!each.empty()) {
    v.push_back(each.top().val);
    each.pop();
  }

  reverse(v.begin(), v.end());

  cout << v.size();
  if (v.size() > 0) {
    for (int i = 0; i < v.size(); i++) {
      cout << " " << v[i];
    }
  }

  cout << endl;

  return 0;
}

Error: 0

Fixed submission:

#include "algorithm"
#include "iostream"
#include "stack"
#include "vector"

using namespace std;

struct Mizu {
  int pos, val;
};

int main() {

  stack<int> s;
  stack<Mizu> each;

  char input[20001];
  int ans = 0;

  cin >> input;

  for (int i = 0;; i++) {
    if (input[i] == '\\\\') {
      s.push(i);
    } else if (input[i] == '/') {
      if (!s.empty()) {
        ans += i - s.top();

        Mizu biger;
        biger.pos = s.top();
        biger.val = 0;

        while (!each.empty()) {
          if (each.top().pos < s.top()) {
            break;
          }
          Mizu m;
          m = each.top();
          each.pop();

          biger.pos = m.pos;
          biger.val += m.val;
        }
        biger.val += i - s.top();
        each.push(biger);
        s.pop();
      }
    } else if (input[i] == '_')
      ;
    else
      break;
  }

  cout << ans << endl;

  vector<int> v;

  while (!each.empty()) {
    v.push_back(each.top().val);
    each.pop();
  }

  reverse(v.begin(), v.end());

  cout << v.size() << " ";

  for (int i = 0; i < v.size() - 1; i++) {
    cout << v[i] << " ";
  }
  cout << v[v.size() - 1] << endl;

  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  string A;
  cin >> A;

  stack<int> s;
  stack<pair<int, int>> pairs;

  for (int i = 0; i < A.size(); i++) {
    if (A[i] == '\\\\') {
      s.push(i);
    } else if (A[i] == '/' && !s.empty()) {
      pairs.push(make_pair(s.top(), i));
      s.pop();
    }
  }

  if (pairs.size() == 0) {
    cout << 0 << endl << 0 << endl;
    return 0;
  }

  int sub = 0, leftest = pairs.top().first;
  vector<int> subs;

  for (auto t = pairs.top(); !pairs.empty(); pairs.pop()) {
    t = pairs.top();

    auto left = t.first, right = t.second;

    if (leftest <= left) {
      sub += right - left;
    } else {
      subs.push_back(sub);
      sub = right - left;
      leftest = left;
    }
  }
  if (sub) {
    subs.push_back(sub);
  }

  cout << accumulate(subs.begin(), subs.end(), 0) << endl;

  cout << subs.size() << " ";

  reverse(subs.begin(), subs.end());

  for (int i = 0; i < subs.size(); i++) {
    cout << subs[i] << (i + 1 == subs.size() ? '\\n' : ' ');
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  string A;
  cin >> A;

  stack<int> s;
  stack<pair<int, int>> pairs;

  for (int i = 0; i < A.size(); i++) {
    if (A[i] == '\\\\') {
      s.push(i);
    } else if (A[i] == '/' && !s.empty()) {
      pairs.push(make_pair(s.top(), i));
      s.pop();
    }
  }

  int sub = 0, leftest = pairs.top().first;
  vector<int> subs;

  for (auto t = pairs.top(); !pairs.empty(); pairs.pop()) {
    t = pairs.top();

    auto left = t.first, right = t.second;

    if (leftest <= left) {
      sub += right - left;
    }

    if (left < leftest || pairs.size() == 1) {
      subs.push_back(sub);
      sub = right - left;
      leftest = left;
    }
  }

  cout << accumulate(subs.begin(), subs.end(), 0) << endl;

  cout << subs.size() << " ";

  reverse(subs.begin(), subs.end());

  for (int i = 0; i < subs.size(); i++) {
    cout << subs[i] << (i + 1 == subs.size() ? '\\n' : ' ');
  }
}
Problem p02266 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
  stack<int> S1;
  stack<pair<int, int>> S2;
  int sum = 0;
  vector<int> ans;

  char c;
  for (int i = 0; cin >> c; i++) {
    if (c == '\\\\')
      S1.push(i);
    else if (c == '/' && S1.size() > 0) {
      int j = S1.top();
      S1.pop();
      int a = i - j;
      sum += a;
      while (S2.size() > 0 && S2.top().first > j) {
        a += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(j, a));
    }
  }

  while (S2.size() > 0) {
    ans.push_back(S2.top().second);
    S2.pop();
  }
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size();
  for (int k = 0; k < ans.size(); k++) {
    cout << " " << ans[k];
  }
  cout << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
  stack<int> S1;
  stack<pair<int, int>> S2;
  int sum = 0;
  vector<int> ans;

  char c;
  for (int i = 0; cin >> c; i++) {
    cout << c << endl;
    if (c == '\\\\')
      S1.push(i);
    else if (c == '/' && S1.size() > 0) {
      int j = S1.top();
      S1.pop();
      int a = i - j;
      sum += a;
      while (S2.size() > 0 && S2.top().first > j) {
        a += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(j, a));
    }
  }

  while (S2.size() > 0) {
    ans.push_back(S2.top().second);
    S2.pop();
  }
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size();
  for (int as : ans) {
    cout << " " << as;
  }
  cout << endl;

  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

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

int main(int argc, char const *argv[]) {
  stack<pair<int, char>> S;
  int section_num = 0;
  int pool_sum = 0;

  string input;
  std::cin >> input;
  ;

  vector<pair<int, int>> pools;
  pools.reserve(20000);

  for (size_t i = 0; i < input.length(); i++) {
    if (input[i] == '_') {
      continue;
    } else if (input[i] == '\\\\') {
      pair<int, char> p = make_pair(i, input[i]);
      S.push(p);
    } else if (input[i] == '/') {
      if (S.empty()) {
        continue;
      }
      pair<int, char> l = S.top();
      S.pop();
      int left = l.first;
      pair<int, int> section = make_pair(left, i);
      pools.push_back(section);
      section_num++;
      pool_sum += i - left;
    }
  }

  std::cout << pool_sum << '\\n';

  sort(pools.begin(), pools.end());

  std::vector<int> pool_section;
  pool_section.push_back(0);

  int pool_num = 0;
  pair<int, int> L = make_pair(pools[0].first, pools[0].second);

  for (size_t j = 0; j < section_num; j++) {
    if (L.first <= pools[j].first && pools[j].second <= L.second) {
      pool_section[pool_num] += pools[j].second - pools[j].first;
    } else {
      pool_section.push_back(pools[j].second - pools[j].first);
      L = pools[j];
      pool_num++;
    }
  }

  if (pool_sum != 0) {
    std::cout << pool_num + 1;
    for (size_t i = 0; i <= pool_num; i++) {
      std::cout << ' ' << pool_section[i];
    }
  } else {
    std::cout << "0";
  }

  std::cout << '\\n';

  return 0;
}


Error: 0

Fixed submission:

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

int main(int argc, char const *argv[]) {
  stack<pair<int, char>> S;
  int section_num = 0;
  int pool_sum = 0;

  string input;
  std::cin >> input;
  ;

  vector<pair<int, int>> pools;

  for (size_t i = 0; i < input.length(); i++) {
    if (input[i] == '_') {
      continue;
    } else if (input[i] == '\\\\') {
      pair<int, char> p = make_pair(i, input[i]);
      S.push(p);
    } else if (input[i] == '/') {
      if (S.empty()) {
        continue;
      }
      pair<int, char> l = S.top();
      S.pop();
      int left = l.first;
      pair<int, int> section = make_pair(left, i);
      pools.push_back(section);
      section_num++;
      pool_sum += i - left;
    }
  }

  std::cout << pool_sum << '\\n';

  sort(pools.begin(), pools.end());

  std::vector<int> pool_section;
  pool_section.push_back(0);

  int pool_num = 1;
  pair<int, int> L = make_pair(pools[0].first, pools[0].second);

  for (size_t j = 0; j < section_num; j++) {
    if (L.first <= pools[j].first && pools[j].second <= L.second) {
      pool_section[pool_num - 1] += pools[j].second - pools[j].first;
    } else {
      pool_section.push_back(pools[j].second - pools[j].first);
      L = pools[j];
      pool_num++;
    }
  }
  std::cout << pool_num;

  for (size_t i = 0; i < pool_num; i++) {
    std::cout << ' ' << pool_section[i];
  }
  std::cout << '\\n';

  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  stack<int> S1;
  stack<pair<int, int>> S2;
  int sum = 0, l, a = 0;
  ;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '\\\\')
      S1.push(i);
    else if (s[i] == '/' && !S1.empty()) {
      l = S1.top();
      S1.pop();
      sum += i - l;
      a = i - l;
      while (!S2.empty() && l < S2.top().first) {
        a += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(l, a));
    }
  }
  if (S2.empty())
    cout << "0\\n"
         << "0\\n";
  else {
    vector<int> x;
    while (!S2.empty()) {
      x.push_back(S2.top().second);
      S2.pop();
    }
    reverse(x.begin(), x.end());
    cout << sum << "\\n";
    cout << x.size() << " ";
    for (int i = 0; i < x.size() - 1; i++)
      cout << x[i] << " ";
    cout << x[x.size() - 1] << "\\n";
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  stack<int> S1;
  stack<pair<int, int>> S2;
  int sum = 0, l, a = 0;
  ;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '\\\\')
      S1.push(i);
    else if (s[i] == '/' && !S1.empty()) {
      l = S1.top();
      S1.pop();
      sum += i - l;
      a = i - l;
      while (!S2.empty() && l < S2.top().first) {
        a += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(l, a));
    }
  }
  vector<int> x;
  while (!S2.empty()) {
    x.push_back(S2.top().second);
    S2.pop();
  }
  reverse(x.begin(), x.end());
  cout << sum << "\\n";
  cout << x.size() << " ";
  for (int i = 0; i < x.size() - 1; i++)
    cout << x[i] << " ";
  cout << x[x.size() - 1] << "\\n";
  return 0;
}
Problem p02266 (C++) — buggy submission, verdict: Runtime Error

/*
** 本题使用两个stack，一个用来统计总积水，一个用来统计单独的积水面积。
*/

#include <cstdio>
#include <stack>
#include <vector>
using namespace std;

static const int maxn = 20000 + 10;

char buff[maxn];

int main() {
  // freopen("data.in", "r", stdin);
  // freopen("data.out", "w", stdout);
  while (scanf("%s", buff) != EOF) {
    /*
    ** ts用来存储每一个'\\'字符的位置，然后当出现'/'字符的时候，通过距离计算积水面积
    ** ps用来存储每一个'\\'所对应的积水面积，默认是0，当出现'/'后，再把面积加进去
    */
    stack<int> ts, ps;
    int sum = 0;
    for (int i = 0; buff[i] != '\\0'; i++) {
      if (buff[i] == 92) { // 92 是 '\\'的 ascii码值
        ts.push(i);
        ps.push(0);
      } else if (buff[i] == 47 && !ts.empty()) { // 47 是 '/'的 ascii码值
        int s = i - ts.top();
        ts.pop();
        sum += s;
        while (ps.top() != 0) {
          s += ps.top();
          ps.pop();
        }
        ps.pop();
        ps.push(s);
      }
    }

    printf("%d\\n", sum);
    vector<int> v;
    while (!ps.empty()) {
      if (ps.top() != 0)
        v.push_back(ps.top());
      ps.pop();
    }
    if (v.size() == 0)
      printf("0\\n");
    else {
      printf("%d ", v.size());
      for (int i = v.size() - 1; i > 0; i--)
        printf("%d ", v[i]);
      printf("%d\\n", v[0]);
    }
  }
  return 0;
}


Error: 0

Fixed submission:

/*
** 本题使用两个stack，一个用来统计总积水，一个用来统计单独的积水面积。
*/

#include <cstdio>
#include <stack>
#include <vector>
using namespace std;

static const int maxn = 20000 + 10;

char buff[maxn];

int main() {
  // freopen("data.in", "r", stdin);
  // freopen("data.out", "w", stdout);
  while (scanf("%s", buff) != EOF) {
    /*
    ** ts用来存储每一个'\\'字符的位置，然后当出现'/'字符的时候，通过距离计算积水面积
    ** ps用来存储每一个'\\'所对应的积水面积，默认是0，当出现'/'后，再把面积加进去
    */
    stack<int> ts, ps;
    int sum = 0;
    for (int i = 0; buff[i] != '\\0'; i++) {
      if (buff[i] == 92) { // 92 是 '\\'的 ascii码值
        ts.push(i);
        ps.push(0);
      } else if (buff[i] == 47 && !ts.empty()) { // 47 是 '/'的 ascii码值
        int s = i - ts.top();
        ts.pop();
        sum += s;
        while (ps.top() != 0) {
          s += ps.top();
          ps.pop();
        }
        ps.pop();
        ps.push(s);
      }
    }

    printf("%d\\n", sum);
    vector<int> v;
    while (!ps.empty()) {
      if (ps.top() != 0)
        v.push_back(ps.top());
      ps.pop();
    }
    printf("%d ", v.size());
    for (int i = v.size() - 1; i > 0; i--)
      printf("%d ", v[i]);
    printf("%d\\n", v[0]);
  }
  return 0;
}