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

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;

int main(int argc, char *argv[]) {
  int n;
  while (cin >> n, n) {
    string s[1001];
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      for (int j = 0; j < s[i].length(); j++) {
        if (s[i][j] == '.') {
          if (s[i][j + 1] != '.') {
            s[i][j] = '+';
            int t = i;
            while (s[--t][j] == ' ')
              s[t][j] = '|';
          } else
            s[i][j] = ' ';
        }
      }
    }
    for (int i = 0; i < n; i++) {
      std::cout << s[i] << std::endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;

int main(int argc, char *argv[]) {
  int n;
  while (cin >> n, n) {
    string s[1001];
    int depth = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      depth = max(depth, (int)s[i].length());
      for (int j = 0; j < s[i].length(); j++) {
        if (s[i][j] != '.')
          break;
        if (s[i][j + 1] != '.')
          s[i][j] = '+';
        else
          s[i][j] = ' ';
      }
    }

    for (int i = 0; i <= depth; i++) {
      for (int j = n - 1; j >= 0; j--) {
        if (s[j][i] == '+') {
          while (s[--j][i] == ' ')
            s[j][i] = '|';
          j++;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      std::cout << s[i] << std::endl;
    }
  }
  return 0;
}
Problem p01695 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void dfs(vector<string> &s, int node, int l, int r) {
  if (l >= r)
    return;
  int a = -1;
  bool f = false;
  for (int i = 0; i < r; i++) {
    if (node < s[i].size() && s[i][node] == '.') {
      f = true;
      if (node + 1 < s[i].size() && isalpha(s[i][node + 1])) {
        s[i][node] = '+';
        if (a == -1)
          a = i + 1;
        else {
          for (int j = a; j < i; j++)
            if (node < s[j].size())
              s[j][node] = '|';
          dfs(s, node + 1, a, i);
          a = i + 1;
        }
      }
    }
  }
  if (f)
    dfs(s, node + 1, l, r);
}

int main(void) {
  int n;
  while (cin >> n && n) {
    vector<string> s(n);
    for (int i = 0; i < n; i++)
      cin >> s[i];

    dfs(s, 0, 0, n);

    for (int i = 0; i < n; i++)
      for (int j = 0; j < s[i].size(); j++)
        if (s[i][j] == '.')
          s[i][j] = ' ';

    for (int i = 0; i < n; i++)
      cout << s[i] << endl;
  }
}

Error: WA

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void dfs(vector<string> &s, int node, int l, int r) {
  // printf("l=%d r=%d\\n",l,r);
  if (l >= r)
    return;
  int a = -1;
  bool f = false;
  for (int i = 0; i < r; i++) {
    if (node < s[i].size() && s[i][node] == '.') {
      f = true;
      if (node + 1 < s[i].size() && s[i][node + 1] != '.') {
        s[i][node] = '+';
        if (a == -1)
          a = i + 1;
        else {
          // printf("a=%d i=%d\\n",a,i);
          for (int j = a; j < i; j++)
            s[j][node] = '|';
          dfs(s, node + 1, a, i);
          a = i + 1;
        }
      }
    }
  }
  if (f)
    dfs(s, node + 1, l, r);
}

int main(void) {
  int n;
  while (cin >> n && n) {
    vector<string> s(n);
    for (int i = 0; i < n; i++)
      cin >> s[i];

    dfs(s, 0, 0, n);

    for (int i = 0; i < n; i++)
      for (int j = 0; j < s[i].size(); j++)
        if (s[i][j] == '.')
          s[i][j] = ' ';

    for (int i = 0; i < n; i++)
      cout << s[i] << endl;
  }
}
Problem p01695 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    string s;
    char thread[1010][1100];
    int len[2][1010];

    memset(thread, ' ', sizeof(thread));
    memset(len, 0, sizeof(len));

    cin >> s;
    for (int j = 0; j < (int)s.size(); j++)
      thread[0][j] = s[j];
    len[1][0] = (int)s.size();

    for (int i = 1; i < n; i++) {
      cin >> s;
      int p = 0;

      for (int j = 0; j < (int)s.size(); j++)
        if (s[j] != '.') {
          p = j;
          break;
        }

      s = "+" + s.substr(p);

      for (int j = p; j < p + (int)s.size(); j++)
        thread[i][j - 1] = s[j - p];

      len[0][i] = p - 1;
      len[1][i] = p + (int)s.size() - 1;
    }

    for (int i = 1; i < n; i++) {
      bool flag = false;
      for (int j = i + 1; j < n; j++) {
        if (isalpha(thread[j][len[0][i]]))
          break;
        if (thread[j][len[0][i]] == '+') {
          flag = true;
          break;
        }
      }

      if (!flag)
        continue;

      for (int j = i + 1; j < n; j++) {
        if (thread[j][len[0][i]] == '+' || isalpha(thread[j][len[0][i]]))
          break;
        thread[j][len[0][i]] = '|';
      }
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < len[1][i]; j++) {
        cout << thread[i][j];
      }
      cout << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    string s;
    char thread[1010][55];
    int len[2][1010];

    memset(thread, ' ', sizeof(thread));
    memset(len, 0, sizeof(len));

    cin >> s;
    for (int j = 0; j < (int)s.size(); j++)
      thread[0][j] = s[j];
    len[1][0] = (int)s.size();

    for (int i = 1; i < n; i++) {
      cin >> s;
      int p = 0;

      for (int j = 0; j < (int)s.size(); j++)
        if (s[j] != '.') {
          p = j;
          break;
        }

      s = "+" + s.substr(p);

      for (int j = p; j < p + (int)s.size(); j++)
        thread[i][j - 1] = s[j - p];

      len[0][i] = p - 1;
      len[1][i] = p + (int)s.size() - 1;
    }

    for (int i = 0; i < n; i++) {
      bool flag = false;
      for (int j = i + 1; j < n; j++) {
        if (thread[j][len[0][i]] == '+') {
          flag = true;
          break;
        }
      }

      if (!flag)
        continue;

      for (int j = i + 1; j < n; j++) {
        if (thread[j][len[0][i]] == '+' || isalpha(thread[j][len[0][i]]))
          break;
        thread[j][len[0][i]] = '|';
      }
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < len[1][i]; j++) {
        cout << thread[i][j];
      }
      cout << endl;
    }
  }

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

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    cin.ignore();
    string s[2005];
    rep(i, n) { cin >> s[i]; }

    rep(i, n) {
      rep(j, s[i].size() - 1) {
        if (s[i][j] == '.' && s[i][j + 1] != '.')
          s[i][j] = '+';
      }
    }

    rep(i, n) {
      rep(j, s[i].size() - 1) {
        int last = 0;
        if (s[i][j] == '+') {
          for (int k = i - 1; s[k][j] == '.'; k--) {
            s[k][j] = '|';
          }
        }
      }
    }

    rep(i, n) {
      rep(j, s[i].size()) {
        if (s[i][j] == '.')
          s[i][j] = ' ';
      }
    }
    rep(i, n) cout << s[i] << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    cin.ignore();
    string s[1005];
    rep(i, n) { cin >> s[i]; }

    rep(i, n) {
      rep(j, s[i].size() - 1) {
        if (s[i][j] == '.' && s[i][j + 1] != '.')
          s[i][j] = '+';
      }
    }

    range(i, 1, n) {
      rep(j, s[i].size() - 1) {
        int last = 0;
        if (s[i - 1][j] == '+') {
          rep(k, n) {
            if (s[i + k][j] == '+')
              last = i + k;
          }
          for (int k = i; k <= last; k++) {
            if (last == 0)
              break;
            if (s[k][j] == '.')
              s[k][j] = '|';
          }
        }
      }
    }

    rep(i, n) {
      rep(j, s[i].size()) {
        if (s[i][j] == '.')
          s[i][j] = ' ';
      }
    }
    rep(i, n) cout << s[i] << endl;
  }
}
Problem p01696 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define N 100
#define M 26
using namespace std;
string s, a;
int p, l, c;

string bnf() {
  string r;
  c = 0;
  while (p != l) {
    char t = s[p];
    if (t == '+')
      p++, c++;
    if (t == '-')
      p++, c--;
    if ('A' <= t && t <= 'Z')
      r += ((s[p++] + c + M * N) - 'A') % M + 'A', c = 0;
    if (t == '?')
      r += s[p++], c = 0;
    if (t == '[')
      p++, r += bnf();
    if (t == ']') {
      p++;
      reverse(r.begin(), r.end());
      break;
    }
  }
  return r;
}

int main() {
  while (1) {
    cin >> s;
    if (s == ".")
      break;
    l = s.size();
    p = 0;
    a = bnf();
    for (int i = 0; i < a.size(); i++)
      if (a[i] == '?')
        a[i] = 'A';
    cout << a << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define N 100
#define M 26
using namespace std;
string s, r, a;
int p, l, i, c;

string bnf() {
  c = 0;
  while (p != l) {
    char t = s[p];
    if (t == '+')
      p++, c++;
    if (t == '-')
      p++, c--;
    if ('A' <= t && t <= 'Z')
      r += ((s[p++] + c + M * N) - 'A') % M + 'A', c = 0;
    if (t == '?')
      r += s[p++], c = 0;
    if (t == '[')
      p++, r += bnf();
    if (t == ']') {
      p++;
      reverse(r.begin(), r.end());
      break;
    }
  }
  return r;
}

int main() {
  while (1) {
    cin >> s;
    if (s == ".")
      break;
    l = s.size();
    p = 0;
    a = bnf();
    for (i = 0; i < a.size(); i++)
      if (a[i] == '?')
        a[i] = 'A';
    cout << a << endl;
  }
  return 0;
}
Problem p01696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

string inde(string s) {
  string ret;
  int c = 0;
  for (auto x : s) {
    if (x == '[')
      ret += '[';
    else if (x == ']')
      ret += ']';
    else if (x == '+')
      c++;
    else if (x == '-')
      c--;
    else if (x == '?') {
      ret += 'A';
      c = 0;
    } else {
      c %= 26;
      ret += (x - 'A' + c + 26) % 26 + 'A';
      c = 0;
    }
  }
  return ret;
}

string rev(string s) {
  int nest = 0;
  int start = 0;
  string ret;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '[') {
      if (nest == 0)
        start = i + 1;
      nest++;
    } else if (s[i] == ']') {
      nest--;
      if (nest == 0) {
        string rstr = rev(s.substr(start, i - start));
        ret += string(rstr.rbegin(), rstr.rend());
      }
    } else if (nest == 0) {
      ret += s[i];
    }
  }
  return ret;
}

int main() {
  string s;
  while (cin >> s, s != ".") {
    cout << rev(inde(s)) << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

string inde(string s) {
  string ret;
  int c = 0;
  for (auto x : s) {
    if (x == '[')
      ret += '[';
    else if (x == ']')
      ret += ']';
    else if (x == '+')
      c++;
    else if (x == '-')
      c--;
    else if (x == '?') {
      ret += 'A';
      c = 0;
    } else {
      ret += (x - 'A' + c + 26) % 26 + 'A';
      c = 0;
    }
  }
  return ret;
}

string rev(string s) {
  int nest = 0;
  int start = 0;
  string ret;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '[') {
      if (nest == 0)
        start = i + 1;
      nest++;
    } else if (s[i] == ']') {
      nest--;
      string rstr = rev(s.substr(start, i - start));
      if (nest == 0)
        ret += string(rstr.rbegin(), rstr.rend());
    } else if (nest == 0) {
      ret += s[i];
    }
  }
  return ret;
}

int main() {
  string s;
  while (cin >> s, s != ".") {
    cout << rev(inde(s)) << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;

long long gcd(long long a, long long b) {
  if (a == 0 || b == 0)
    return 1ll;
  while (b)
    swap(a = a % b, b);
  return a;
}

struct Ratio {
  long long d, n;
  Ratio(long long d_ = 0, long long n_ = 1) : d(d_), n(n_) {}
  Ratio &operator+=(Ratio other) {
    return *this = reduct(Ratio(d * other.n + other.d * n, n * other.n));
  }
  Ratio &operator-=(Ratio other) {
    return *this = reduct(Ratio(d * other.n - other.d * n, n * other.n));
  }
  friend Ratio operator+(const Ratio &lhs, const Ratio &rhs) {
    Ratio t(lhs);
    return t += rhs;
  }
  friend Ratio operator-(const Ratio &lhs, const Ratio &rhs) {
    Ratio t(lhs);
    return t -= rhs;
  }
  friend Ratio reduct(Ratio r) {
    long long g = gcd(r.d, r.n);
    Ratio t(r.d / g, r.n / g);
    if (t.n < 0)
      t.d = -t.d, t.n = -t.n;
    return t;
  }
  friend ostream &operator<<(ostream &os, const Ratio &r) {
    if (r.n == 1)
      return os << r.d;
    return os << r.d << '/' << r.n;
  }
};

inline bool endswith(const string &s, const string &t) {
  return s.size() < t.size() ? false
                             : s.compare(s.size() - t.size(), t.size(), t) == 0;
}

Ratio solve(const string &dir) {
  Ratio a(0);
  for (int l = int(dir.size()), n = 0; l > 0; ++n) {
    if (endswith(dir.substr(0, l), "west"))
      a += Ratio(90, 1 << n), l -= 4;
    else
      a -= n ? Ratio(90, 1 << n) : 0, l -= 5;
  }
  return a;
}

int main() {
  for (string dir; cin >> dir, dir != "#";)
    cout << solve(dir) << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

template <class T> T gcd(T a, T b) {
  while (b)
    swap(a = a % b, b);
  return a;
}

struct Ratio {
  int d, n;
  Ratio(int d_ = 0, int n_ = 1) : d(d_), n(n_) {}
  Ratio &operator+=(Ratio other) {
    d = d * other.n + other.d * n;
    n *= other.n;
    return *this;
  }
  Ratio &operator-=(Ratio other) {
    d = d * other.n - other.d * n;
    n *= other.n;
    return *this;
  }
  friend Ratio operator+(const Ratio &lhs, const Ratio &rhs) {
    Ratio t(lhs);
    return t += rhs;
  }
  friend Ratio operator-(const Ratio &lhs, const Ratio &rhs) {
    Ratio t(lhs);
    return t -= rhs;
  }
  friend Ratio operator-(Ratio r) { return Ratio(-r.d, r.n); }
  friend Ratio reduct(Ratio &&r) {
    int g = gcd(r.d, r.n);
    r.d /= g;
    r.n /= g;
    return r;
  }
  friend ostream &operator<<(ostream &os, const Ratio &r) {
    if (r.n == 1)
      return os << r.d;
    return os << r.d << '/' << r.n;
  }
};

bool startswith(const string &s, const string &t) {
  return s.size() < t.size() ? false : s.compare(0, t.size(), t) == 0;
}

Ratio solve(const string &dir, int &n) {
  if (dir == "north") {
    n++;
    return 0;
  }
  if (dir == "west") {
    n++;
    return 90;
  }
  if (startswith(dir, "north"))
    return -Ratio(90, 1 << n++) + solve(dir.substr(5), n);
  if (startswith(dir, "west"))
    return Ratio(90, 1 << n++) + solve(dir.substr(4), n);
}

int main() {
  for (string dir; cin >> dir, dir != "#";) {
    int n = 0;
    cout << reduct(solve(dir, n)) << endl;
  }
}
Problem p01701 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
  string in;
  while (cin >> in, in != "#") {
    string s = "";
    rep(i, in.length()) {
      if (in[i] == 'w') {
        i += 3;
        s += "w";
      } else {
        i += 4;
        s += "n";
      }
    }
    reverse(s.begin(), s.end());
    int a = 0;
    rep(i, s.length()) {
      a *= 2;
      if (s[i] == 'w') {
        a += 90;
      } else {
        a -= 90;
        if (a < 0)
          a = 0;
      }
    }
    int b = 1 << (s.length() - 1);
    int g = __gcd(a, b);
    a /= g;
    b /= g;
    cout << a;
    if (b > 1) {
      cout << '/' << b;
    }
    cout << endl;
  }
  return 0;
}

Error: -8

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int gcd(int a, int b) {
  if (b > a)
    swap(a, b);
  while (a != b) {
    if (a % b == 0)
      return b;
    a = a % b;
    swap(a, b);
  }
  return b;
}

int main() {
  string in;
  while (cin >> in, in != "#") {
    string s = "";
    rep(i, in.length()) {
      if (in[i] == 'w') {
        i += 3;
        s += 'w';
      } else {
        i += 4;
        s += 'n';
      }
    }
    double a = 0.0;
    double div = 1.0;
    rep(i, s.length()) {
      if (s[i] == 'w') {
        a += 90.0 / div;
      } else {
        a -= 90.0 / div;
      }
      if (a < 0.0)
        a = 0.0;
      if (a > 90.0)
        a = 90.0;
      div *= 2.0;
    }
    int p = (int)pow(2.0, s.length() - 1);
    a *= p;
    if (a < 0.0) {
      a = 0.0;
    } else {
      int g = gcd((int)a, p);
      a /= g;
      p /= g;
    }
    cout << (int)a;
    if (p > 1) {
      cout << '/' << p;
    }
    cout << endl;
  }
  return 0;
}
Problem p01701 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  while (cin >> s, s != "#") {
    int a = 0, b = 1, i = 0, c, d;
    vector<int> v;
    while (i < s.size()) {
      v.push_back(s[i] == 'w' ? 1 : 0);
      i += (s[i] == 'w' ? 4 : 5);
    }
    reverse(v.begin(), v.end());
    a = v[0];
    for (int j = 1; j < v.size(); j++) {
      a *= 2;
      b *= 2;
      a += (v[j] ? 1 : -1);
    }
    a *= 90;
    c = a;
    d = b;
    while (d) {
      c %= d;
      swap(c, d);
    }
    cout << a / c;
    if (b != c)
      cout << "/" << b / c;
    cout << endl;
  }
}

Error: -8

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  while (cin >> s, s[0] != '#') {
    int a = 0, b = 1, i = 0, c, d;
    while (i < s.size()) {
      if (s[i] == 'w') {
        a *= 2;
        if (a != 90 * b)
          a += 90;
        i += 4;
      } else {
        a = a * 2 - (a ? 90 : 0);
        i += 5;
      }
      b *= 2;
    }
    b /= 2;
    c = a;
    d = b;
    while (c && d) {
      c %= d;
      swap(c, d);
    }
    cout << a / c;
    if (b != c)
      cout << "/" << b / c;
    cout << endl;
  }
}
Problem p01701 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  string t;
  while (cin >> t) {
    string s;
    if (t == "#")
      break;
    for (int i = t.size() - 1; i >= 0; i--) {
      if (t[i] == 'n')
        s += "north";
      if (t[i] == 'w')
        s += "west";
    }

    int m = 1, i, c;
    char t = s[0];
    if (t == 'n')
      c = 0, i = 5;
    else
      c = 90, i = 4;
    int f = 1;
    while (i != s.size()) {
      c *= 2;
      m *= 2;
      // cout<<c<<" "<<m<<endl;
      if (t == s[i] && f) {
        if (s[i] == 'n')
          i += 5;
        else
          i += 4;
        continue;
      }
      f = 0;
      if (s[i] == 'n')
        c -= 90, i += 5;
      else
        c += 90, i += 4;
    }
    int g = __gcd(c, m);
    cout << c / g;
    if (m / g != 1)
      cout << "/" << m / g;
    cout << endl;
  }
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  while (cin >> s) {
    if (s == "#")
      break;
    int m = 1, i, c;
    char t = s[0];
    if (t == 'n')
      c = 0, i = 5;
    else
      c = 90, i = 4;
    int f = 1;
    while (i != s.size()) {
      cout << c << " " << m << endl;
      c *= 2;
      m *= 2;
      if (t == s[i] && f) {
        if (s[i] == 't')
          i += 5;
        else
          i += 4;
        t = 0;
        continue;
      }
      f = 0;
      if (s[i] == 'n')
        c -= 90, i += 5;
      else
        c += 90, i += 4;
    }
    c = abs(c);
    int g = __gcd(c, m);
    cout << c / g;
    if (m / g != 1)
      cout << "/" << m / g;
    cout << endl;
  }
  return 0;
}
Problem p01701 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#include <string>
using namespace std;
string S, T;
int x[100], n, m, L[3], R, M;
int main() {
  while (true) {
    cin >> S;
    n = 0;
    m = 0;
    if (S == "#") {
      break;
    }
    M = 0;
    for (int i = S.size() - 1; i >= 0; i--) {
      T += S[i];
    }

    S = T;
    T = "";

    while (n < S.size()) {
      if (S[n] == 'h') {
        n += 5;
        x[m] = 0;
      } else {
        n += 4;
        x[m] = 1;
      }
      m++;
    }

    L[0] = 0;
    L[1] = 90 * (1 << 20);

    if (x[0] == 0) {
      L[0] = 0;
    } else {
      L[0] = L[1];
    }

    for (int i = 1; i < m; i++) {
      L[1] /= 2;
      if (x[i] == 1) {
        L[0] += L[1];
      } else {
        L[0] -= L[1];
      }
      if (L[0] < 0) {
        L[0] = 0;
      }
      if (L[0] > 90 * (1 << 20)) {
        L[0] = 90;
      }
    }
    R = L[0];
    M = (1 << 20);
    while (R % 2 == 0 && M >= 2) {
      R /= 2;
      M /= 2;
    }
    cout << R;
    if (M >= 2) {
      cout << '/' << M;
    }
    cout << endl;
  }
}

Error: WA

Fixed submission:

#include <cmath>
#include <iostream>
#include <string>
using namespace std;
string S;
int x[10], n, m;
double L[3];
int main() {
  while (true) {
    cin >> S;
    n = 0;
    m = 1;
    if (S == "#") {
      break;
    }
    while (n < S.size()) {
      if (S[n] == 'n') {
        n += 5;
        x[m] = 0;
      } else {
        n += 4;
        x[m] = 1;
      }
      m++;
    }
    L[0] = 0;
    L[1] = 90;
    for (int i = 1; i < m - 1; i++) {
      L[2] = (L[1] + L[0]) / 2;
      L[1 - x[i]] = L[2];
    }
    cout << L[x[m - 1]] << endl;
  }
}