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

#include <bits/stdc++.h>
using namespace std;
char sb[100];
char s[100];
int stsy(int, int, int, int);
int pr(int, int);
int ka(int, int);
int main() {
  while (1) {
    cin >> sb;
    if (sb[0] == '.')
      break;
    int co = 0;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        for (int k = 0; k < 3; k++) {
          strcpy(s, sb);
          int ans;
          //   cout <<i<<j<<k <<" ";
          ans = stsy(0, i, j, k);
          //	  cout << ans << endl;
          if (ans == 2)
            co++;
        }
      }
    }
    cout << co << endl;
  }
  return 0;
}
int stsy(int I, int p, int q, int r) {
  int d = -1;
  int d2 = -1;
  int mi = 0;
  int t = 0;
  int x = 0;
  while (1) {
    // cout << s[I] ;
    if (s[I] == ')' || s[I] == '\\0')
      return d2;
    else if (s[I] == '(') {
      d = stsy(I + 1, p, q, r);
      for (; s[I] != ')'; I++)
        ;
      s[I] = 'x';

    } else if (s[I] == '-') {
      if (mi == 0)
        mi = 1;
      else
        mi = 0;
    } else if (s[I] == 'P')
      d = p;
    else if (s[I] == 'Q')
      d = q;
    else if (s[I] == 'R')
      d = r;
    else if (s[I] == '0')
      d = 0;
    else if (s[I] == '1')
      d = 1;
    else if (s[I] == '2')
      d = 2;
    else if (s[I] == '+')
      t = 1;
    else if (s[I] == '*')
      x = 1;
    if (d != -1 && mi == 1) {
      if (d == 2)
        d = 0;
      else if (d == 0)
        d = 2;
      mi = 0;
    }
    if (t == 1 && d != -1) {
      d2 = pr(d, d2);
      //  cout << " "<<d2 <<'+'<< " ";
      d = -1;
      t = 0;
    }
    if (x == 1 && d != -1) {
      d2 = ka(d, d2);
      d = -1;
      x = 0;
    }
    if (d != -1) {
      d2 = d;
    }
    d = -1;
    I++;
  }
}
int pr(int a, int b) { return max(a, b); }
int ka(int a, int b) { return min(a, b); }

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
char sb[100];
char s[100];
bool ch(int, int, int);
int stsy(char *, int, int, int);
int pr(int, int);
int ka(int, int);
int main() {
  while (1) {
    cin >> sb;
    if (s[0] == '.')
      break;
    int co = 0;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        for (int k = 0; k < 3; k++) {
          for (int l = 0; l < 100; l++) {
            s[l] = sb[l];
          }
          int ans;
          ans = stsy(s, i, j, k);
          if (ans == 2)
            co++;
        }
      }
    }
    cout << co << endl;
  }
  return 0;
}
/*bool ch(int a,int b,int c){
  int re;
  re=stsy(s,0,1,2);
  cout << a <<" "<< b <<" "<<c <<" " << re << endl;
  if(re==2)return 1;
  return 0;
}
*/
int stsy(char *cp, int p, int q, int r) {
  // static int cou=0;
  // cou++;
  // cout << cou<< endl;
  int d = -1;
  int d2 = -1;
  int mi = 0;
  int t = 0;
  int x = 0;
  while (1) {
    // cout << *cp << endl;
    if (*cp == ')' || *cp == '\\0')
      return d2;
    else if (*cp == '(') {
      d = stsy(cp + 1, p, q, r);
      for (; *cp != ')'; cp++)
        ;
      *cp = 'x';
      cp++;
    } else if (*cp == '-') {
      if (mi == 0)
        mi = 1;
      else
        mi = 0;
    } else if (*cp == 'P')
      d = p;
    else if (*cp == 'Q')
      d = q;
    else if (*cp == 'R')
      d = r;
    else if (*cp == '0')
      d = 0;
    else if (*cp == '1')
      d = 1;
    else if (*cp == '2')
      d = 2;
    else if (*cp == '+')
      t = 1;
    else if (*cp == '*')
      x = 1;
    //
    if (d != -1 && mi == 1) {
      if (d == 2)
        d = 0;
      else if (d == 0)
        d = 2;
    }
    if (t == 1 && d != -1) {
      d2 = pr(d, d2);
      d = -1;
      t = 0;
    }
    if (x == 1 && d != -1) {
      d2 = ka(d, d2);
      d = -1;
      x = 0;
    }
    if (d != -1) {
      d2 = d;
    }
    d = -1;
    cp++;
  }
}
int pr(int a, int b) {
  // cout << "tasu" << endl;
  if (a == 0)
    return b;
  if (a == 2 || b == 2)
    return 2;
  return 1;
}
int ka(int a, int b) {
  //  cout << "kakeru" << endl;
  // cout << a << b << endl;
  if (a == 0 || b == 0)
    return 0;
  if (a == 2 && b == 2)
    return 2;
  return 1;
}