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

#include <cctype>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <string>

using namespace std;

int min(char *s) {
  int n = 0;
  int sum = 0, tmpI = 0;
  bool flag = true;
  list<int> intlist;

  for (int i = 0; s[i] != '\\0'; i++) {
    if (s[i] == '[') {
      int count = 1, j;
      for (j = 1; count != 0; j++) {
        if (s[j + i] == '[') {
          count += 1;
        } else if (s[j + i] == ']') {
          count -= 1;
        }
      }
      // cout << "Weeeei" << endl;
      char *tmpS = new char[10000];
      strncpy(tmpS, s + i + 1, j - 2);
      tmpS[j - 2] = '\\0';
      // cout << tmpS << endl;
      int x = min(tmpS);
      intlist.push_back(x);
      n++;
      flag = false;
      i = i + j - 1;
      delete[] tmpS;
    }
  }
  if (flag) {
    tmpI = atoi(s);
    // cout << tmpI << endl;
    return tmpI / 2 + 1;
  }

  intlist.sort();

  list<int>::iterator itr = intlist.begin();
  for (int i = 0; i < n / 2 + 1; itr++, i++) {
    sum += *itr;
  }

  /*
  bool flag = true;
  for(int i = 0; s[i] != '\\n'; i++) {
          if(s[i] == '[') {
                  if(!flag) {
                          string s2;
                          for(int j = 0; s[j] != ']' && s[j + 1] != ']'; j++) {
                                  strncpy(s2, s+i, j-i+1);
                          }
                          min(s2);
                  } else {
                          n++:
                          flag = false;
                  }
          }
  }

  int[] input = new input[n];
  int j = 0;
  for(int i = 0; s[i] != '\\n'; i++) {
          if(s[i] == '[') {
                  ;
          } else if(s[i] == ']') {
                  input[j] = tmpI;
                  tmpI = 0;
          } else {
                  tmpI = tmpI * 10 + atoi(c);
          }
  }
  sort(input);
  for(int i = 0; i < n/2 + 1; i++) {
          sum = input[i] / 2 + 1;
  }
  */

  return sum;
}

int main(void) {
  int n;
  cin >> n;

  // cout << "ok" << endl;
  for (int i = 0; i < n; i++) {
    char *s = new char[10002];
    // char c;
    // int j = 0;
    /*for( ; cin >> c && (c != '\\n' && c != '\\0'); j++) {
            s[j] = c;
    }
    s[j] = '\\0';
    */
    cin >> s;
    // cout << s;
    // cout << "abon" << endl;

    cout << min(s) << endl;
    delete[] s;
  }
}

Error: WA

Fixed submission:

#include <cctype>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <string>

using namespace std;

int min(char *s) {
  int n = 0;
  int sum = 0, tmpI = 0;
  bool flag = true;
  list<int> intlist;

  for (int i = 0; s[i] != '\\0'; i++) {
    if (s[i] == '[') {
      int count = 1, j;
      for (j = 1; count != 0; j++) {
        if (s[j + i] == '[') {
          count += 1;
        } else if (s[j + i] == ']') {
          count -= 1;
        }
      }
      // cout << "Weeeei" << endl;
      char *tmpS = new char[1000];
      strncpy(tmpS, s + i + 1, j - 2);
      int x = min(tmpS);
      intlist.push_back(x);
      n++;
      flag = false;
      i = i + j - 1;
    }
  }
  if (flag) {
    tmpI = atoi(s);
    // cout << tmpI << endl;
    return tmpI / 2 + 1;
  }

  intlist.sort();

  list<int>::iterator itr = intlist.begin();
  for (int i = 0; i < n / 2 + 1; itr++, i++) {
    sum += *itr;
  }

  /*
  bool flag = true;
  for(int i = 0; s[i] != '\\n'; i++) {
          if(s[i] == '[') {
                  if(!flag) {
                          string s2;
                          for(int j = 0; s[j] != ']' && s[j + 1] != ']'; j++) {
                                  strncpy(s2, s+i, j-i+1);
                          }
                          min(s2);
                  } else {
                          n++:
                          flag = false;
                  }
          }
  }

  int[] input = new input[n];
  int j = 0;
  for(int i = 0; s[i] != '\\n'; i++) {
          if(s[i] == '[') {
                  ;
          } else if(s[i] == ']') {
                  input[j] = tmpI;
                  tmpI = 0;
          } else {
                  tmpI = tmpI * 10 + atoi(c);
          }
  }
  sort(input);
  for(int i = 0; i < n/2 + 1; i++) {
          sum = input[i] / 2 + 1;
  }
  */

  return sum;
}

int main(void) {
  int n;
  cin >> n;

  cout << "ok" << endl;
  for (int i = 0; i < n; i++) {
    char *s = new char[10002];
    char c;
    int j = 0;
    /*for( ; cin >> c && (c != '\\n' && c != '\\0'); j++) {
            s[j] = c;
    }
    s[j] = '\\0';
    */
    cin >> s;
    // cout << s;
    // cout << "abon" << endl;

    cout << min(s) << endl;
  }
}