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

#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define f first
#define s second
#define mp make_pair

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

#define MAX 1010

int main() {
  char buff[100];
  while (fgets(buff, sizeof(buff), stdin)) {
    stack<double> st;
    for (char *p = buff; *p; p++)
      if (*p == '\\n')
        *p = '\\0';
    for (char *p = buff; *p; p++) {
      if (*p == '+') {
        double op1, op2;
        op1 = st.top();
        st.pop();
        op2 = st.top();
        st.pop();
        st.push(op1 + op2);
      } else if (*p == '-' && (*(p + 1) < '0' || *(p + 1) > '9')) {
        double op1, op2;
        op2 = st.top();
        st.pop();
        op1 = st.top();
        st.pop();
        st.push(op1 - op2);
      } else if (*p == '*') {
        double op1, op2;
        op1 = st.top();
        st.pop();
        op2 = st.top();
        st.pop();
        st.push(op1 * op2);
      } else if (*p == '/') {
        double op1, op2;
        op2 = st.top();
        st.pop();
        op1 = st.top();
        st.pop();
        st.push(op1 / op2);
      } else if (*p == ' ') {
      } else {
        double op;
        sscanf(p, "%lf", &op);
        st.push(op);
        while ((*p >= '0' && *p <= '9') || (*p == '.') || (*p == '-'))
          p++;
      }
    }
    printf("%.6f\\n", st.top());
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define f first
#define s second
#define mp make_pair

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

#define MAX 1010

int main() {
  char buff[100];
  while (fgets(buff, sizeof(buff), stdin)) {
    stack<double> st;
    for (char *p = buff; *p; p++)
      if (*p == '\\n')
        *p = '\\0';
    for (char *p = buff; *p; p++) {
      if (*p == '+') {
        double op1, op2;
        op1 = st.top();
        st.pop();
        op2 = st.top();
        st.pop();
        st.push(op1 + op2);
      } else if (*p == '-') {
        double op1, op2;
        op2 = st.top();
        st.pop();
        op1 = st.top();
        st.pop();
        st.push(op1 - op2);
      } else if (*p == '*') {
        double op1, op2;
        op1 = st.top();
        st.pop();
        op2 = st.top();
        st.pop();
        st.push(op1 * op2);
      } else if (*p == '/') {
        double op1, op2;
        op2 = st.top();
        st.pop();
        op1 = st.top();
        st.pop();
        st.push(op1 / op2);
      } else if (*p == ' ') {
      } else {
        double op;
        sscanf(p, "%lf", &op);
        st.push(op);
        while ((*p >= '0' && *p <= '9') || (*p == '.'))
          p++;
      }
    }
    printf("%.6f\\n", st.top());
  }
  return 0;
}