prithivMLmods/Coder-Stat huggingface dataset:
Problem p00086 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, const char *argv[]) {
  while (1) {
    vector<int> G[100];
    int a, b;
    while (1) {
      if (!cin >> a >> b) {
        return 0;
      }
      if (a == 0 && b == 0) {
        break;
      }
      a--;
      b--;
      G[a].push_back(b);
      G[b].push_back(a);
    }
    if (G[0].size() % 2 == 1 && G[1].size() % 2 == 1) {
      int c = 0;
      for (int i = 0; i < 100; i++) {
        if (G[i].size() % 2 == 1) {
          c++;
        }
      }
      if (c == 2) {
        cout << "OK" << endl;
      } else {
        cout << "NG" << endl;
      }
    } else {
      cout << "NG" << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, const char *argv[]) {
  while (1) {
    vector<int> G[100];
    int a, b;
    while (1) {
      if (!(cin >> a >> b)) {
        return 0;
      }
      if (a == 0 && b == 0) {
        break;
      }
      a--;
      b--;
      G[a].push_back(b);
      G[b].push_back(a);
    }
    if (G[0].size() % 2 == 1 && G[1].size() % 2 == 1) {
      int c = 0;
      for (int i = 0; i < 100; i++) {
        if (G[i].size() % 2 == 1) {
          c++;
        }
      }
      if (c == 2) {
        cout << "OK" << endl;
      } else {
        cout << "NG" << endl;
      }
    } else {
      cout << "NG" << endl;
    }
  }
  return 0;
}
Problem p00086 (C++)

Buggy submission (status: Runtime Error):
// coding on smartphone
#include <iostream>
using namespace std;

int main() {
  int a, b;
  while (cin >> a >> b) {
    int deg[51] = {};
    deg[a]++, deg[b]++;
    while (cin >> a >> b, a + b)
      deg[a]++, deg[b]++;
    bool judge = deg[1] % 2 == 1 && deg[2] % 2 == 1;
    for (int i = 3; i < 51; i++)
      if (deg[i] % 2)
        judge = false;
    if (judge)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}


Fixed submission:
// coding on smartphone
#include <iostream>
using namespace std;

int main() {
  int a, b;
  while (cin >> a >> b) {
    int deg[101] = {};
    deg[a]++, deg[b]++;
    while (cin >> a >> b, a + b)
      deg[a]++, deg[b]++;
    bool judge = deg[1] % 2 == 1 && deg[2] % 2 == 1;
    for (int i = 3; i < 51; i++)
      if (deg[i] % 2)
        judge = false;
    if (judge)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}
Problem p00087 (C++)

Buggy submission (status: Runtime Error):
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>

double calc(char op, double a, double b) {
  switch (op) {
  case '+':
    return a + b;
  case '-':
    return a - b;
  case '*':
    return a * b;
  case '/':
    return a / b;
  }
}

int main() {
  std::string str;
  while (std::getline(std::cin, str)) {
    std::stack<double> s;
    std::istringstream iss(str);
    std::string item;

    while (iss >> item) {
      if (item[0] == '+' || item[0] == '-' || item[0] == '*' ||
          item[0] == '/') {
        double b = s.top();
        s.pop();
        double a = s.top();
        s.pop();

        s.push(calc(item[0], a, b));
      } else
        s.push(atof(item.c_str()));
    }

    std::cout << std::fixed << std::setprecision(6) << s.top() << std::endl;
  }

  return 0;
}

Fixed submission:
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>

double calc(char op, double a, double b) {
  switch (op) {
  case '+':
    return a + b;
  case '-':
    return a - b;
  case '*':
    return a * b;
  case '/':
    return a / b;
  }
}

int main() {
  std::string str;
  while (std::getline(std::cin, str)) {
    std::stack<double> s;
    std::istringstream iss(str);
    std::string item;

    while (iss >> item) {
      if (item == "+" || item == "-" || item == "*" || item == "/") {
        double b = s.top();
        s.pop();
        double a = s.top();
        s.pop();

        s.push(calc(item[0], a, b));
      } else
        s.push(atof(item.c_str()));
    }

    std::cout << std::fixed << std::setprecision(6) << s.top() << std::endl;
  }

  return 0;
}
Problem p00087 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

/*
int stringToint(const string S)
{
   int result=0;
   if(S[0]=='-')
   {
     for(int i=1;i<S.length();i++)
     {
       result=10*result+(S[i]-'0');
     }
     result=-result;
   }
   else
   {
     for(int i=0;i<S.length();i++)
     {
       result=10*result+(S[i]-'0');
     }
   }
   return result;
}
*/

int main() {
  string s;
  string word;
  stack<double> mm;
  while (cin >> word) {
    if (word == "+" || word == "-" || word == "*" || word == "/") {
      double a = mm.top();
      mm.pop();
      double b = mm.top();
      mm.pop();
      double result;
      if (word == "+")
        result = b + a;
      else if (word == "-")
        result = b - a;
      else if (word == "*")
        result = b * a;
      else
        result = b / a;
      mm.push(result);
    } else if (word.length() == 2 && word[0] == '-' || (isdigit(word[0]))) {
      // double kk=1.0*(stringToint(word));
      mm.push(atoi(word.c_str()));
      // mm.push(kk);
    }
    if (getchar() == '\n') {
      double final_result = mm.top();
      printf("%.10lf\n", final_result);
      mm.pop();
    }
  }
  // while(1);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

/*
int stringToint(const string S)
{
   int result=0;
   if(S[0]=='-')
   {
     for(int i=1;i<S.length();i++)
     {
       result=10*result+(S[i]-'0');
     }
     result=-result;
   }
   else
   {
     for(int i=0;i<S.length();i++)
     {
       result=10*result+(S[i]-'0');
     }
   }
   return result;
}
*/

int main() {
  string s;
  string word;
  stack<double> mm;
  while (cin >> word) {
    if (word == "+" || word == "-" || word == "*" || word == "/") {
      double a = mm.top();
      mm.pop();
      double b = mm.top();
      mm.pop();
      double result;
      if (word == "+")
        result = b + a;
      else if (word == "-")
        result = b - a;
      else if (word == "*")
        result = b * a;
      else
        result = b / a;
      mm.push(result);
    } else if (word.length() >= 2 && word[0] == '-' || (isdigit(word[0]))) {
      // double kk=1.0*(stringToint(word));
      mm.push(atoi(word.c_str()));
      // mm.push(kk);
    }
    if (getchar() == '\n') {
      double final_result = mm.top();
      printf("%.10lf\n", final_result);
      mm.pop();
    }
  }
  // while(1);
  return 0;
}
Problem p00087 (C++)

Buggy submission (status: Runtime Error):
#include <iomanip>
#include <iostream>
#include <stack>
#include <string>
using namespace std;
string S, U[1000];
stack<double> T;
int cnt;
double a, b;
int main() {
  while (getline(cin, S)) {
    cnt = 0;
    for (int i = 0; i < S.size(); i++) {
      if (S[i] == ' ') {
        cnt++;
      } else {
        U[cnt] += S[i];
      }
    }
    cnt++;
    for (int i = 0; i < cnt; i++) {
      if (U[i] == "+") {
        a = T.top();
        T.pop();
        b = T.top();
        T.pop();
        T.push(a + b);
      } else if (U[i] == "-") {
        a = T.top();
        T.pop();
        b = T.top();
        T.pop();
        T.push(b - a);
      } else if (U[i] == "*") {
        a = T.top();
        T.pop();
        b = T.top();
        T.pop();
        T.push(a * b);
      } else if (U[i] == "/") {
        a = T.top();
        T.pop();
        b = T.top();
        T.pop();
        T.push(b / a);
      } else {
        T.push(stoi(U[i]));
      }
    }
    cout << fixed << setprecision(20) << T.top() << endl;
    T.pop();
  }
}

Fixed submission:
#include <iomanip>
#include <iostream>
#include <stack>
#include <string>
using namespace std;
string S, U[1000];
stack<double> T;
int cnt;
double a, b;
int main() {
  while (getline(cin, S)) {
    for (int i = 0; i < 1000; i++) {
      U[i] = "";
    }
    cnt = 0;
    for (int i = 0; i < S.size(); i++) {
      if (S[i] == ' ') {
        cnt++;
      } else {
        U[cnt] += S[i];
      }
    }
    cnt++;
    for (int i = 0; i < cnt; i++) {
      if (U[i] == "+") {
        a = T.top();
        T.pop();
        b = T.top();
        T.pop();
        T.push(a + b);
      } else if (U[i] == "-") {
        a = T.top();
        T.pop();
        b = T.top();
        T.pop();
        T.push(b - a);
      } else if (U[i] == "*") {
        a = T.top();
        T.pop();
        b = T.top();
        T.pop();
        T.push(a * b);
      } else if (U[i] == "/") {
        a = T.top();
        T.pop();
        b = T.top();
        T.pop();
        T.push(b / a);
      } else {
        T.push(stoi(U[i]));
      }
    }
    cout << fixed << setprecision(20) << T.top() << endl;
    T.pop();
  }
}
Problem p00087 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
using namespace std;

int main() {
  string s;
  while (getline(cin, s)) {
    stringstream ss(s);
    stack<double> stk;
    while (ss >> s) {
      if (isdigit(s[0])) {
        stk.push(atof(s.c_str()));
      } else {
        double b = stk.top();
        stk.pop();
        double a = stk.top();
        stk.pop();
        double res = 0;
        switch (s[0]) {
        case '+':
          res = a + b;
          break;
        case '-':
          res = a - b;
          break;
        case '*':
          res = a * b;
          break;
        case '/':
          res = a / b;
          break;
        }
        stk.push(res);
      }
    }
    printf("%.10f\n", stk.top());
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
using namespace std;

int main() {
  string s;
  while (getline(cin, s)) {
    stringstream ss(s);
    stack<double> stk;
    while (ss >> s) {
      if (isdigit(*s.rbegin())) {
        stk.push(atof(s.c_str()));
      } else {
        double b = stk.top();
        stk.pop();
        double a = stk.top();
        stk.pop();
        double res = 0;
        switch (s[0]) {
        case '+':
          res = a + b;
          break;
        case '-':
          res = a - b;
          break;
        case '*':
          res = a * b;
          break;
        case '/':
          res = a / b;
          break;
        }
        stk.push(res);
      }
    }
    printf("%.10f\n", stk.top());
  }
  return 0;
}
Problem p00087 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y)                                                            \
  cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
#define BINARY(x) static_cast<bitset<16>>(x)

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)

#define in_range(x, y, w, h)                                                   \
  (0 <= (int)(x) && (int)(x) < (int)(w) && 0 <= (int)(y) && (int)(y) < (int)(h))
#define ALL(a) (a).begin(), (a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4] = {0, -1, 1, 0}, dy[4] = {-1, 0, 0, 1};

int main() {
  string line;
  while (true) {
    getline(cin, line);
    if (cin.eof())
      break;

    stack<double> st;
    stringstream ss(line);
    while (!ss.eof()) {
      string S;
      ss >> S;

      if (isdigit(S[0])) {
        int num = stoi(S);
        st.push(num);
      } else {
        double b = st.top();
        st.pop();
        double a = st.top();
        st.pop();
        if (S == "-")
          st.push(a - b);
        if (S == "+")
          st.push(a + b);
        if (S == "*")
          st.push(a * b);
        if (S == "/")
          st.push(a / b);
      }
    }

    cout << fixed << setprecision(10) << st.top() << endl;
  }
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y)                                                            \
  cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
#define BINARY(x) static_cast<bitset<16>>(x)

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)

#define in_range(x, y, w, h)                                                   \
  (0 <= (int)(x) && (int)(x) < (int)(w) && 0 <= (int)(y) && (int)(y) < (int)(h))
#define ALL(a) (a).begin(), (a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4] = {0, -1, 1, 0}, dy[4] = {-1, 0, 0, 1};

int main() {
  string line;
  while (true) {
    getline(cin, line);
    if (cin.eof())
      break;

    stack<double> st;
    stringstream ss(line);
    while (!ss.eof()) {
      string S;
      ss >> S;

      if (isdigit(S[0]) || S.size() > 1) {
        int num = stoi(S);
        st.push(num);
      } else {
        double b = st.top();
        st.pop();
        double a = st.top();
        st.pop();
        if (S == "-")
          st.push(a - b);
        if (S == "+")
          st.push(a + b);
        if (S == "*")
          st.push(a * b);
        if (S == "/")
          st.push(a / b);
      }
    }

    cout << fixed << setprecision(10) << st.top() << endl;
  }
}
Problem p00087 (C++)

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  while (true) {
    stack<double> s;
    char In[81];
    double num = 0;
    bool is_pos = true;
    int r;
    for (int i = 0; r = scanf("%c", &In[i]); i++) {
      if (In[i] == '\n')
        break;
      if (r == EOF)
        return 0;
    }
    for (int i = 0; In[i] != '\n'; i++) {
      if (In[i] == ' ')
        continue;
      if ('0' <= In[i] && In[i] <= '9') {
        num = num * 10 + (In[i] - '0');
        if (In[i + 1] == ' ') {
          if (is_pos == false)
            num *= -1;
          s.push(num);
          num = 0;
          is_pos = true;
        }
      } else {
        if (In[i] == '-' && '0' <= In[i + 1] && In[i + 1] <= '9') {
          is_pos = false;
        } else {
          double a, b;
          b = s.top();
          s.pop();
          a = s.top();
          s.pop();
          if (In[i] == '+')
            s.push(a + b);
          else if (In[i] == '-')
            s.push(a - b);
          else if (In[i] == '*')
            s.push(a * b);
          else
            s.push(a / b);
        }
      }
    }
    printf("%lf\n", s.top());
  }
  return 0;
}

Fixed submission:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  while (true) {
    stack<double> s;
    char In[81];
    double num = 0;
    bool is_pos = true;
    int r;
    for (int i = 0; r = scanf("%c", &In[i]); i++) {
      if (In[i] == '\n')
        break;
      if (r == EOF)
        return 0;
    }
    for (int i = 0; In[i] != '\n'; i++) {
      if (In[i] == ' ')
        continue;
      if ('0' <= In[i] && In[i] <= '9') {
        num = num * 10 + (In[i] - '0');
        if (In[i + 1] < '0' || '9' < In[i + 1]) {
          if (is_pos == false)
            num *= -1;
          s.push(num);
          num = 0;
          is_pos = true;
        }
      } else {
        if (In[i] == '-' && '0' <= In[i + 1] && In[i + 1] <= '9') {
          is_pos = false;
        } else {
          double a, b;
          b = s.top();
          s.pop();
          a = s.top();
          s.pop();
          if (In[i] == '+')
            s.push(a + b);
          else if (In[i] == '-')
            s.push(a - b);
          else if (In[i] == '*')
            s.push(a * b);
          else
            s.push(a / b);
        }
      }
    }
    printf("%lf\n", s.top());
  }
  return 0;
}
Problem p00087 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main() {
  double x, y;
  string s;
  while (getline(cin, s)) {
    stack<double> box;
    s = s + '\0';
    for (int i = 0; i < (int)s.size() - 1; i++) {
      if (s[i] == '-') {
        if (!isdigit(s[i + 1])) {
          x = box.top();
          box.pop();
          y = box.top();
          box.pop();
          box.push(y - x);
        } else {
          box.push(-atof(&s[i + 1]));
          for (i += 1; s[i] != ' '; i++)
            ;
        }
      } else if (s[i] == '+') {
        x = box.top();
        box.pop();
        y = box.top();
        box.pop();
        box.push(y + x);
      } else if (s[i] == '*') {
        x = box.top();
        box.pop();
        y = box.top();
        box.pop();
        box.push(y * x);
      } else if (s[i] == '/') {
        x = box.top();
        box.pop();
        y = box.top();
        box.pop();
        box.push(y / x);
      } else if (isdigit(s[i])) {
        box.push(atof(&s[i]));
        for (; s[i] != ' '; i++)
          ;
      }
    }
    if (!box.empty()) {
      printf("%.6lf\n", box.top());
    }
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main() {
  double x, y;
  string s;
  while (getline(cin, s)) {
    stack<double> box;
    s = s + ' ';
    for (int i = 0; i < (int)s.size() - 1; i++) {
      if (s[i] == '-') {
        if (!isdigit(s[i + 1])) {
          x = box.top();
          box.pop();
          y = box.top();
          box.pop();
          box.push(y - x);
        } else {
          box.push(-atof(&s[i + 1]));
          for (i += 1; s[i] != ' '; i++)
            ;
        }
      } else if (s[i] == '+') {
        x = box.top();
        box.pop();
        y = box.top();
        box.pop();
        box.push(y + x);
      } else if (s[i] == '*') {
        x = box.top();
        box.pop();
        y = box.top();
        box.pop();
        box.push(y * x);
      } else if (s[i] == '/') {
        x = box.top();
        box.pop();
        y = box.top();
        box.pop();
        box.push(y / x);
      } else if (isdigit(s[i])) {
        box.push(atof(&s[i]));
        for (; s[i] != ' '; i++)
          ;
      }
    }
    if (!box.empty()) {
      printf("%.6lf\n", box.top());
    }
  }
  return 0;
}
Problem p00087 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
using namespace std;

int main() {
  string str;

  while (getline(cin, str)) {
    stack<double> st;
    stringstream ss;

    ss << str;
    string item;
    while (ss >> item) {
      char c = item.at(0);

      if (c == '+' || c == '-' || c == '*' || c == '/') {
        double a, b;

        b = st.top();
        st.pop();
        a = st.top();
        st.pop();
        if (c == '+')
          st.push(a + b);
        else if (c == '-')
          st.push(a - b);
        else if (c == '*')
          st.push(a * b);
        else
          st.push(a / b);
      } else {
        st.push(atof(item.c_str()));
      }
    }
    printf("%f\n", st.top());
  }

  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
using namespace std;

int main() {
  string str;

  while (getline(cin, str)) {
    stack<double> st;
    stringstream ss;

    ss << str;
    string item;
    while (ss >> item) {
      char c = item.at(0);

      if (c == '+' || (c == '-' && item.length() == 1) || c == '*' ||
          c == '/') {
        double a, b;

        b = st.top();
        st.pop();
        a = st.top();
        st.pop();
        if (c == '+')
          st.push(a + b);
        else if (c == '-')
          st.push(a - b);
        else if (c == '*')
          st.push(a * b);
        else
          st.push(a / b);
      } else {
        st.push(atof(item.c_str()));
      }
    }
    printf("%f\n", st.top());
  }

  return 0;
}
Problem p00087 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <sstream>
#include <stack>
#include <string>

using namespace std;

int main() {
  string str;
  while (getline(cin, str)) {
    stack<double> S;
    stringstream sin(str);
    string temp;
    while (sin >> temp) {
      switch (temp[0]) {
        double a, b;
      case '+':
        a = S.top();
        S.pop();
        b = S.top();
        S.pop();
        S.push(b + a);
        break;
      case '-':
        a = S.top();
        S.pop();
        b = S.top();
        S.pop();
        S.push(b - a);
        break;
      case '*':
        a = S.top();
        S.pop();
        b = S.top();
        S.pop();
        S.push(b * a);
        break;
      case '/':
        a = S.top();
        S.pop();
        b = S.top();
        S.pop();
        S.push(b / a);
        break;
      default:
        stringstream s1(temp);
        double d;
        s1 >> d;
        S.push(d);
      }
    }
    printf("%.6f\n", S.top());
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <sstream>
#include <stack>
#include <string>

using namespace std;

int main() {
  string str;
  while (getline(cin, str)) {
    stack<double> S;
    stringstream sin(str);
    string temp;
    while (sin >> temp) {
      bool flag = false;
      if (temp.length() == 1) {
        flag = true;
        switch (temp[0]) {
          double a, b;
        case '+':
          a = S.top();
          S.pop();
          b = S.top();
          S.pop();
          S.push(b + a);
          break;
        case '-':
          a = S.top();
          S.pop();
          b = S.top();
          S.pop();
          S.push(b - a);
          break;
        case '*':
          a = S.top();
          S.pop();
          b = S.top();
          S.pop();
          S.push(b * a);
          break;
        case '/':
          a = S.top();
          S.pop();
          b = S.top();
          S.pop();
          S.push(b / a);
          break;
        default:
          flag = false;
        }
      }
      if (!flag) {
        stringstream s1(temp);
        double d;
        s1 >> d;
        S.push(d);
      }
    }
    printf("%.6f\n", S.top());
  }
  return 0;
}
Problem p00087 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define reps(i, f, n) for (int i = f; i < int(n); i++)
#define rep(i, n) reps(i, 0, n)

int main() {
  while (1) {
    string str;
    getline(cin, str);

    if (cin.eof())
      break;

    vector<bool> isnum;
    rep(i, str.size()) {
      if (i == 0 || str[i - 1] == ' ') {
        char c = str[i];
        if (c >= '0' && c <= '9')
          isnum.push_back(true);
        else
          isnum.push_back(false);
      }
    }

    stringstream sst;
    sst << str;

    stack<double> t;
    rep(i, isnum.size()) {
      if (isnum[i]) {
        int a;
        sst >> a;
        t.push((double)a);

      } else {
        char c;
        sst >> c;

        double b = t.top();
        t.pop();
        double a = t.top();
        t.pop();

        if (c == '*') {
          t.push(a * b);
        }
        if (c == '+') {

          t.push(a + b);
        }
        if (c == '-') {

          t.push(a - b);
        }
        if (c == '/') {

          t.push(a / b);
        }
      }
    }

    printf("%.8lf\n", t.top());
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define reps(i, f, n) for (int i = f; i < int(n); i++)
#define rep(i, n) reps(i, 0, n)

int main() {
  while (1) {
    string str;
    getline(cin, str);

    if (cin.eof())
      break;

    vector<bool> isnum;
    rep(i, str.size()) {
      if (i == str.size() - 1 || str[i + 1] == ' ') {
        char c = str[i];
        if (c >= '0' && c <= '9')
          isnum.push_back(true);
        else
          isnum.push_back(false);
      }
    }

    stringstream sst;
    sst << str;

    stack<double> t;
    rep(i, isnum.size()) {
      if (isnum[i]) {
        int a;
        sst >> a;
        t.push((double)a);

      } else {
        char c;
        sst >> c;

        double b = t.top();
        t.pop();
        double a = t.top();
        t.pop();

        if (c == '*') {
          t.push(a * b);
        }
        if (c == '+') {

          t.push(a + b);
        }
        if (c == '-') {

          t.push(a - b);
        }
        if (c == '/') {

          t.push(a / b);
        }
      }
    }

    printf("%.8lf\n", t.top());
  }
}
Problem p00087 (C++)

Buggy submission (status: Runtime Error):
// Name: Strange Mathematical Expression
// Level: 1
// Category: 逆ポーランド記法,やるだけ
// Note:

#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);

  string line;
  while (getline(cin, line) && !cin.eof()) {
    istringstream is(line);
    stack<double> stk;
    string token;
    while (is >> token) {
      if (isdigit(token[0])) {
        stk.push(atof(token.c_str()));
      } else {
        double b = stk.top();
        stk.pop();
        double a = stk.top();
        stk.pop();
        switch (token[0]) {
        case '+':
          stk.push(a + b);
          break;
        case '-':
          stk.push(a - b);
          break;
        case '*':
          stk.push(a * b);
          break;
        case '/':
          stk.push(a / b);
          break;
        }
      }
    }
    printf("%.10f\n", stk.top());
  }
  return 0;
}

Fixed submission:
// Name: Strange Mathematical Expression
// Level: 1
// Category: 逆ポーランド記法,やるだけ
// Note:

#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);

  string line;
  while (getline(cin, line) && !cin.eof()) {
    istringstream is(line);
    stack<double> stk;
    string token;
    while (is >> token) {
      if (isdigit(token[0]) || token.size() >= 2) {
        stk.push(atof(token.c_str()));
      } else {
        double b = stk.top();
        stk.pop();
        double a = stk.top();
        stk.pop();
        switch (token[0]) {
        case '+':
          stk.push(a + b);
          break;
        case '-':
          stk.push(a - b);
          break;
        case '*':
          stk.push(a * b);
          break;
        case '/':
          stk.push(a / b);
          break;
        }
      }
    }
    printf("%.10f\n", stk.top());
  }
  return 0;
}
Problem p00087 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
using namespace std;
#define rep2(x, from, to) for (int x = (from); x < (to); ++(x))
#define rep(x, to) rep2(x, 0, to)
int main() {
  string str;
  while (getline(cin, str)) {
    stack<double> s;
    stringstream ss;
    ss << str;
    while (ss >> str) {
      if (str[0] >= '0' && str[0] <= '9' || s.size() > 1) {
        s.push(atoi(str.c_str()));
      } else {
        double a = s.top();
        s.pop();
        double b = s.top();
        s.pop();
        double c;
        if (str[0] == '+')
          c = a + b;
        else if (str[0] == '-')
          c = b - a;
        else if (str[0] == '*')
          c = a * b;
        else
          c = b / a;
        s.push(c);
      }
    }
    printf("%.6lf\n", s.top());
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
using namespace std;
#define rep2(x, from, to) for (int x = (from); x < (to); ++(x))
#define rep(x, to) rep2(x, 0, to)
int main() {
  string str;
  while (getline(cin, str)) {
    stack<double> s;
    stringstream ss;
    ss << str;
    while (ss >> str) {
      if (str[0] >= '0' && str[0] <= '9' || str.length() > 1) {
        s.push(atoi(str.c_str()));
      } else {
        double a = s.top();
        s.pop();
        double b = s.top();
        s.pop();
        double c;
        if (str[0] == '+')
          c = a + b;
        else if (str[0] == '-')
          c = b - a;
        else if (str[0] == '*')
          c = a * b;
        else
          c = b / a;
        s.push(c);
      }
    }
    printf("%.6lf\n", s.top());
  }
  return 0;
}
Problem p00087 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>

using namespace std;
#define rep2(x, from, to) for (int x = (from); x < (to); ++(x))
#define rep(x, to) rep2(x, 0, to)
int main() {
  string str;
  while (getline(cin, str)) {
    stack<double> s;
    stringstream ss;
    ss << str;
    while (ss >> str) {
      if (isdigit(str[0])) {
        s.push(atoi(str.c_str()));
      } else {
        double a = s.top();
        s.pop();
        double b = s.top();
        s.pop();
        double c;
        if (str[0] == '+')
          c = a + b;
        else if (str[0] == '-')
          c = b - a;
        else if (str[0] == '*')
          c = a * b;
        else
          c = b / a;
        s.push(c);
      }
    }
    printf("%.6lf\n", s.top());
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>

using namespace std;
#define rep2(x, from, to) for (int x = (from); x < (to); ++(x))
#define rep(x, to) rep2(x, 0, to)
int main() {
  string str;
  while (getline(cin, str)) {
    stack<double> s;
    stringstream ss;
    ss << str;
    while (ss >> str) {
      if (isdigit(str[0]) || str.length() > 1) {
        s.push(atoi(str.c_str()));
      } else {
        double a = s.top();
        s.pop();
        double b = s.top();
        s.pop();
        double c;
        if (str[0] == '+')
          c = a + b;
        else if (str[0] == '-')
          c = b - a;
        else if (str[0] == '*')
          c = a * b;
        else
          c = b / a;
        s.push(c);
      }
    }
    printf("%.6lf\n", s.top());
  }
  return 0;
}
Problem p00087 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  for (;;) {
    string s;
    getline(cin, s);
    if (s.size() == 0)
      return 0;

    istringstream iss(s);
    stack<double> stk;
    for (;;) {
      string s1;
      if (iss >> s1) {
        if ('0' <= s1[0] && s1[0] <= '9')
          stk.push(atof(s1.c_str()));
        else {
          double x = stk.top();
          stk.pop();
          double y = stk.top();
          stk.pop();
          if (s1 == "+")
            stk.push(y + x);
          else if (s1 == "-")
            stk.push(y - x);
          else if (s1 == "*")
            stk.push(y * x);
          else
            stk.push(y / x);
        }
      } else
        break;
    }
    printf("%.10f\n", stk.top());
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  for (;;) {
    string s;
    getline(cin, s);
    if (s.size() == 0)
      return 0;

    istringstream iss(s);
    stack<double> stk;
    for (;;) {
      string s1;
      if (iss >> s1) {
        if (s1.size() > 1 || ('0' <= s1[0] && s1[0] <= '9'))
          stk.push(atof(s1.c_str()));
        else {
          double x = stk.top();
          stk.pop();
          double y = stk.top();
          stk.pop();
          if (s1 == "+")
            stk.push(y + x);
          else if (s1 == "-")
            stk.push(y - x);
          else if (s1 == "*")
            stk.push(y * x);
          else
            stk.push(y / x);
        }
      } else
        break;
    }
    printf("%.10f\n", stk.top());
  }
}
Problem p00087 (C++)

Buggy submission (status: Runtime Error):
#include <cctype>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
using namespace std;

int main() {
  string str;
  double a, b;

  while (getline(cin, str)) {
    stack<double> st;
    stringstream ss(str);
    string s;

    a = atof(s.c_str());
    st.push(a);
    while (ss >> s) {
      if (isdigit(s[0])) {
        a = atof(s.c_str());
        st.push(a);
      } else if (s == "+") {
        a = st.top();
        st.pop();
        b = st.top();
        st.pop();
        st.push(b + a);
      } else if (s == "-") {
        a = st.top();
        st.pop();
        b = st.top();
        st.pop();
        st.push(b - a);
      } else if (s == "*") {
        a = st.top();
        st.pop();
        b = st.top();
        st.pop();
        st.push(b * a);
      } else if (s == "/") {
        a = st.top();
        st.pop();
        b = st.top();
        st.pop();
        if (a == 0)
          exit(EXIT_FAILURE);
        st.push(b / a);
      }
    }
    printf("%.6lf\n", st.top());
  }

  return 0;
}

Fixed submission:
#include <cctype>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
using namespace std;

int main() {
  string str;
  double a, b;

  while (getline(cin, str)) {
    stack<double> st;
    stringstream ss(str);
    string s;

    a = atof(s.c_str());
    st.push(a);
    while (ss >> s) {
      if (s.size() > 1 || isdigit(s[0])) {
        a = atof(s.c_str());
        st.push(a);
      } else if (s == "+") {
        a = st.top();
        st.pop();
        b = st.top();
        st.pop();
        st.push(b + a);
      } else if (s == "-") {
        a = st.top();
        st.pop();
        b = st.top();
        st.pop();
        st.push(b - a);
      } else if (s == "*") {
        a = st.top();
        st.pop();
        b = st.top();
        st.pop();
        st.push(b * a);
      } else if (s == "/") {
        a = st.top();
        st.pop();
        b = st.top();
        st.pop();
        if (a == 0)
          exit(EXIT_FAILURE);
        st.push(b / a);
      }
    }
    printf("%.6lf\n", st.top());
  }

  return 0;
}
Problem p00087 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <stack>

using namespace std;

bool isope(char c) { return c == '+' || c == '-' || c == '*' || c == '/'; }

double calc(double a, char c, double b) {
  switch (c) {
  case '+':
    return a + b;
  case '-':
    return a - b;
  case '*':
    return a * b;
  case '/':
    return a / b;
  }
}

int main() {
  while (1) {
    stack<double> st;

    while (1) {
      char s[16];
      int f = scanf("%s", s);
      if (!~f)
        return 0;

      if (isope(s[0])) {
        double b = st.top();
        st.pop();
        double a = st.top();
        st.pop();
        st.push(calc(a, s[0], b));
      } else {
        double a;
        sscanf(s, "%lf", &a);
        st.push(a);
      }

      if (getchar() == '\n')
        break;
    }

    printf("%f\n", st.top());
  }
}

Fixed submission:
#include <cstdio>
#include <stack>

using namespace std;

bool isope(char c) { return c == '+' || c == '-' || c == '*' || c == '/'; }

double calc(double a, char c, double b) {
  switch (c) {
  case '+':
    return a + b;
  case '-':
    return a - b;
  case '*':
    return a * b;
  case '/':
    return a / b;
  }
}

int main() {
  while (1) {
    stack<double> st;

    while (1) {
      char s[16];
      int f = scanf("%s", s);
      if (!~f)
        return 0;

      if (s[1] == '\0' && isope(s[0])) {
        double b = st.top();
        st.pop();
        double a = st.top();
        st.pop();
        st.push(calc(a, s[0], b));
      } else {
        double a;
        sscanf(s, "%lf", &a);
        st.push(a);
      }

      if (getchar() == '\n')
        break;
    }

    printf("%f\n", st.top());
  }
}
Problem p00087 (C++)

Buggy submission (status: Runtime Error):
#include <cctype>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
using namespace std;
int main() {
  string str;
  while (getline(cin, str)) {
    stack<double> S;
    stringstream ss;
    ss << str;
    while (ss >> str) {
      if (isdigit(str[0])) {
        double d = (double)atoi(str.c_str());
        S.push(d);
      } else {
        char ope = str[0];
        double d1 = S.top();
        S.pop();
        double d2 = S.top();
        S.pop();
        if (ope == '+')
          S.push(d1 + d2);
        else if (ope == '-')
          S.push(d2 - d1);
        else if (ope == '*')
          S.push(d1 * d2);
        else
          S.push(d2 / d1);
      }
    }
    cout << fixed << S.top() << endl;
  }
}

Fixed submission:
#include <cctype>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
using namespace std;
int main() {
  string str;
  while (getline(cin, str)) {
    stack<double> S;
    stringstream ss;
    ss << str;
    while (ss >> str) {
      if (str[0] >= '0' && str[0] <= '9' || str.size() > 1) {
        S.push(atoi(str.c_str()));
      } else {
        char ope = str[0];
        double d1 = S.top();
        S.pop();
        double d2 = S.top();
        S.pop();
        if (ope == '+')
          S.push(d1 + d2);
        else if (ope == '-')
          S.push(d2 - d1);
        else if (ope == '*')
          S.push(d1 * d2);
        else
          S.push(d2 / d1);
      }
    }
    cout << fixed << S.top() << endl;
  }
}
Problem p00087 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>
#include <iostream>
#include <stack>
#include <string>
using namespace std;

int main() {
  char str[128];

  while (fgets(str, sizeof(str), stdin) != NULL) {
    stack<double> s;

    for (int i = 0; str[i] && str[i] != '\n';) {
      if (str[i] == ' ')
        i++;
      else if ('0' <= str[i] && str[i] <= '9') {
        int p = 0;
        for (; str[i] && str[i] != ' ' && str[i] != '\n'; i++) {
          p *= 10;
          p += str[i] - '0';
        }
        s.push((double)p);
      }

      else {
        double r, l;
        double p;
        r = s.top();
        s.pop();
        l = s.top();
        s.pop();

        switch (str[i]) {
        case '+':
          p = l + r;
          break;
        case '-':
          p = l - r;
          break;
        case '*':
          p = l * r;
          break;
        case '/':
          p = l / r;
          break;
        }
        s.push(p);
        i++;
      }
    }
    printf("%f\n", s.top());
  }
}

Fixed submission:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <stack>
#include <string>
using namespace std;

int main() {
  char str[128];

  while (fgets(str, sizeof(str), stdin) != NULL) {
    stack<double> s;

    for (int i = 0; str[i] && str[i] != '\n';) {
      if (str[i] == ' ')
        i++;
      else if ('0' <= str[i] && str[i] <= '9') {
        int p = 0;
        for (; str[i] && str[i] != ' ' && str[i] != '\n'; i++) {
          p *= 10;
          p += str[i] - '0';
        }
        s.push((double)p);
      }

      else if (str[i] == '-' && str[i + 1] != ' ' && str[i + 1] != '\n') {
        int p = 0;
        i++;
        for (; str[i] && str[i] != ' ' && str[i] != '\n'; i++) {
          p *= 10;
          p += str[i] - '0';
        }
        s.push((double)p * (-1));
      }

      else {
        double r, l;
        double p;
        r = s.top();
        s.pop();
        l = s.top();
        s.pop();

        switch (str[i]) {
        case '+':
          p = l + r;
          break;
        case '-':
          p = l - r;
          break;
        case '*':
          p = l * r;
          break;
        case '/':
          p = l / r;
          break;
        }
        s.push(p);
        i++;
      }
    }
    printf("%f\n", s.top());
  }
}
Problem p00087 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#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()

int main() {
  string line;
  while (getline(cin, line)) {
    char str[81];
    strcpy(str, line.c_str());
    char *p;
    p = strtok(str, " ");
    stack<double> sk;
    while (p) {
      if (!isdigit(*p)) {
        double tmp2 = sk.top();
        sk.pop();
        double tmp1 = sk.top();
        sk.pop();
        if (*p == '+')
          sk.push(tmp1 + tmp2);
        else if (*p == '-')
          sk.push(tmp1 - tmp2);
        else if (*p == '*')
          sk.push(tmp1 * tmp2);
        else if (*p == '/')
          sk.push(tmp1 / tmp2);
      } else
        sk.push(atof(p));
      p = strtok(NULL, " ");
    }
    printf("%.6lf\n", sk.top());
  }
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#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()

int main() {
  string line;
  while (getline(cin, line)) {
    char str[81];
    strcpy(str, line.c_str());
    char *p;
    p = strtok(str, " ");
    stack<double> sk;
    while (p) {
      if (strlen(p) == 1 && !isdigit(*p)) {
        double tmp2 = sk.top();
        sk.pop();
        double tmp1 = sk.top();
        sk.pop();
        if (*p == '+')
          sk.push(tmp1 + tmp2);
        else if (*p == '-')
          sk.push(tmp1 - tmp2);
        else if (*p == '*')
          sk.push(tmp1 * tmp2);
        else if (*p == '/')
          sk.push(tmp1 / tmp2);
      } else
        sk.push(atof(p));
      p = strtok(NULL, " ");
    }
    printf("%.6lf\n", sk.top());
  }
}
Problem p00088 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string e = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
vector<string> s1 = {"100101",   "10011010", "0101",     "0001",     "110",
                     "01001",    "10011011", "010000",   "0111",     "10011000",
                     "0110",     "00100",    "10011001", "10011110", "00101",
                     "111",      "10011111", "1000",     "00110",    "00111",
                     "10011100", "10011101", "000010",   "10010010", "10010011",
                     "10010000", "101",      "010001",   "000011",   "10010001",
                     "000000",   "000001"};
vector<string> s2 = {
    "00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111",
    "01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111",
    "10000", "10001", "10010", "10011", "10100", "10101", "10110", "10111",
    "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111"};
string s;
int main() {
  while (true) {
    s = "";
    while (s == "")
      getline(cin, s);
    string t;
    for (int i = 0; i < s.size(); i++) {
      for (int j = 0; j < e.size(); j++) {
        if (s[i] == e[j])
          t += s1[j];
      }
    }
    while (t.size() % 5 != 0)
      t += "0";
    string ret = "";
    for (int i = 0; i < t.size(); i += 5) {
      string u = t.substr(i, 5);
      for (int j = 0; j < e.size(); j++) {
        if (u == s2[j])
          ret += e[j];
      }
    }
    cout << ret << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string e = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
vector<string> s1 = {"100101",   "10011010", "0101",     "0001",     "110",
                     "01001",    "10011011", "010000",   "0111",     "10011000",
                     "0110",     "00100",    "10011001", "10011110", "00101",
                     "111",      "10011111", "1000",     "00110",    "00111",
                     "10011100", "10011101", "000010",   "10010010", "10010011",
                     "10010000", "101",      "010001",   "000011",   "10010001",
                     "000000",   "000001"};
vector<string> s2 = {
    "00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111",
    "01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111",
    "10000", "10001", "10010", "10011", "10100", "10101", "10110", "10111",
    "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111"};
string s;
int main() {
  while (s = "", getline(cin, s)) {
    string t;
    for (int i = 0; i < s.size(); i++) {
      for (int j = 0; j < e.size(); j++) {
        if (s[i] == e[j])
          t += s1[j];
      }
    }
    while (t.size() % 5 != 0)
      t += "0";
    string ret = "";
    for (int i = 0; i < t.size(); i += 5) {
      string u = t.substr(i, 5);
      for (int j = 0; j < e.size(); j++) {
        if (u == s2[j])
          ret += e[j];
      }
    }
    cout << ret << endl;
  }
  return 0;
}