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

#include <iostream>
#include <vector>
using namespace std;

int main() {
  double height, low;
  double input;
  vector<double> height_array;
  while (cin >> input) {
    height_array.push_back(input);
  }
  low = height = height_array[0];
  for (int i = 0; i < height_array.size(); i++) {
    double temp;
    if (low >= height_array[i]) {
      low = height_array[i];
    }
    if (height <= height_array[i]) {
      height = height_array[i];
    }
  }
  cout << height - low << endl;
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {
  double height = 0, low = 0;
  double input;
  vector<double> height_array;
  while (1) {
    cin >> input;
    height_array.push_back(input);
  }
  for (int i = 0; i < height_array.size(); i++) {
    double temp;
    if (height < height_array[i]) {
      temp = height_array[i];
      height_array[i] = height;
      height = temp;
    }
    if (low > height_array[i]) {
      low = height_array[i];
    }
  }
  cout << height - low << endl;
  return 0;
}
Problem p00046 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

// 0046
int main() {
  double h;
  vector<double> height;

  while (cin >> h) {

    height.push_back(h);
  }

  sort(height.begin(), height.end());
  double diff = height.back() - height.front();
  cout << diff << endl;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

// 0046
int main() {
  double h;
  vector<double> height;

  while (cin >> h) {
    if (cin.eof())
      break;
    height.push_back(h);
  }

  sort(height.begin(), height.end());
  double diff = height[height.back()] - height[height.front()];
  cout << diff << endl;
}
Problem p00046 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

void Solution() {
  int n = 0;
  double a[100]; // notice the definition.

  while (cin >> a[n]) {
    n++;
  }

  //    for (int i = 0; i < n - 1; i++)
  //    {
  //        for (int j = i + 1; j < n; j++)
  //        {
  //            if (a[i] < a[j])
  //            {
  //                double temp = a[i];          //swap
  //                a[i] = a[j];
  //                a[j] = temp;
  //            }
  //        }
  //    }

  sort(a, a + n); // sorting as ascedning sequence

  // cout.setf(ios::fixed); //"setf" is used for “half-adjusting”
  // cout.precision(2);

  //    cout<<a[0] - a[n - 1]<<endl;
  cout << a[n - 1] - a[0] << endl;
}

int main() {
  Solution();
  return 0;
}

Error: -7

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

void Solution() {
  int n = 0;
  double a[n];

  while (cin >> a[n]) {
    n++;
  }

  //    for (int i = 0; i < n - 1; i++)
  //    {
  //        for (int j = i + 1; j < n; j++)
  //        {
  //            if (a[i] < a[j])
  //            {
  //                double temp = a[i];          //swap
  //                a[i] = a[j];
  //                a[j] = temp;
  //            }
  //        }
  //    }

  sort(a, a + n); // sorting as ascedning sequence

  // cout.setf(ios::fixed); //"setf" is used for “half-adjusting”
  // cout.precision(2);

  //    cout<<a[0] - a[n - 1]<<endl;
  cout << a[n - 1] - a[0] << endl;
}

int main() {
  Solution();
  return 0;
}
Problem p00046 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  float max = 0, min = 1000000, in;
  while (true) {
    cin >> in;
    if (cin.eof()) {
      break;
    }
    if (max < in) {
      max = in;
    } else if (min > in) {
      min = in;
    }
  }
  cout << max - min << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  float max = 0, min = 1000000, in;
  while (true) {
    cin >> in;
    if (max < in) {
      max = in;
    } else if (min > in) {
      min = in;
    }
    cout << max - min << endl;
  }
  return 0;
}
Problem p00046 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int main() {
  vector<double> mts;
  double in;
  string str;
  while (getline(cin, str), str.size()) {
    sscanf(str.c_str(), "%lf", &in);
    mts.push_back(in);
  }
  sort(mts.begin(), mts.end());
  double out = mts[mts.size() - 1] - mts[0];
  cout << out << endl;
  return 0;
}

Error: MLE

Fixed submission:

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

int main() {
  vector<double> mts;
  double in;
  while (cin >> in, in) {
    mts.push_back(in);
  }
  sort(mts.begin(), mts.end());
  double out = mts[mts.size() - 1] - mts[0];
  cout << out << endl;
  return 0;
}
Problem p00046 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

int main() {

  double h;
  vector<double> v;

  while (cin >> h) {

    v.push_back(h);
  }

  sort(v.begin(), v.end());

  cout << v[v.size() - 1] - v[0] << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

int main() {

  double h;
  double h1 = 10000.0;
  double h2 = 0.0;

  while (true) {

    cin >> h;
    if (h == 0.0)
      break;

    if (h <= h1)
      h1 = h;
    if (h >= h2)
      h2 = h;
  }

  cout << h2 - h1 << endl;

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

#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
using namespace std;
int main() {
  double a;
  int i = 0;
  vector<double> dat;
  while (cin >> a) {
    dat.push_back(a);
    i++;
  }
  sort(dat.begin(), dat.end());
  cout << dat[i - 1] - dat[0] << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  double a;
  int i = 0;
  vector<double> data;
  while (cin >> a) {
    data[i] = a;
    i++;
  }
  sort(data.begin(), data.end());
  cout << data[i - 1] - data[0] << endl;
  return 0;
}
Problem p00046 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

#define INF 100000000000.0
using namespace std;

int main(void) {

  double high, min = INF, max = -1 * INF;

  while (scanf("%lf", &high) != EOF) {
    if (max < high)
      max = high;
    if (min > high)
      min = high;
  }

  printf("%.1f\\n", max - min);

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

#define INF 100000000000.0
using namespace std;

int main(void) {

  double high, min = INF, max = -1 * INF;

  while (scanf("%d", &high) != EOF) {
    if (max < high)
      max = high;
    if (min > high)
      min = high;
  }

  printf("%f.1\\n", max - min);

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

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

int main() {
  double a, ma = 0, mi = 100000000000;

  while (cin >> a) {
    ma = max(a, ma);
    mi = min(a, mi);
  }
  cout << ma - mi << endl;
}

Error: WA

Fixed submission:

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int main() {
  int i;
  double a[5];
  for (i = 0; cin >> a[i]; i++)
    ;
  sort(a, a + 1);
  cout << a[i - 1] - a[0] << endl;
}
Problem p00046 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main(void) {
  double a, mx, mn;
  cin >> a;
  mx = mn = a;
  while (1) {
    if (cin.eof()) {
      break;
    }
    cin >> a;
    mx = max(mx, a);
    mn = min(mn, a);
  }
  cout << mx - mn << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main(void) {
  double a, mx, mn;
  cin >> a;
  mx = mn = a;
  while (1) {
    if (cin.eof() == -1) {
      break;
    }
    cin >> a;
    mx = max(mx, a);
    mn = min(mn, a);
  }
  cout << mx - mn << endl;
  return 0;
}
Problem p00046 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  vector<double> v;
  vector<double>::iterator pv = v.begin();
  double d;
  while (cin >> d) {
    v.push_back(d);
  }
  sort(v.begin(), v.end());
  int z = v.size();
  double a = v[z - 1];
  double b = v[0];
  double c = a - b;
  cout << c << endl;
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  vector<double> v;
  vector<double>::iterator pv = v.begin();
  double d;
  while (cin >> d) {
    v.push_back(d);
  }
  sort(v.begin(), v.end());
  double a = *pv;
  pv = v.end();
  double b = *pv;
  cout << b - a << endl;
  return 0;
}
Problem p00046 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {
  double H, max, min;
  max = 0;
  min = 0;
  while (scanf("%lf", &H) != EOF) {

    if (H > max)
      max = H;
    else if (H < min)
      min = H;
    if (min == 0)
      min = H;
  }
  printf("%lf", max - min);
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  double H, max, min;
  max = 0;
  min = 0;
  while (scanf("%d", &H) != EOF) {
    if (H > max)
      max = H;
    if (H < min)
      min = H;
  }
  printf("%.1lf", max - min);
  return 0;
}
Problem p00046 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  double n, h = 0.0, l = 999999.0;

  while (cin >> n) {
    h = max(h, n);
    l = min(l, n);
  }

  printf("%.1lf\\n", h - l);
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  double n, h = 0.0, l = 999999.0;

  while (scanf("%lf", &n)) {
    h = max(h, n);
    l = min(l, n);
  }

  printf("%.1lf\\n", h - l);
}
Problem p00047 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;

int main() {
  string tmp;
  bool a = true, b = false, c = false;
  while (cin >> tmp) {
    if ((tmp[0] == 'A' && tmp[2] == 'B') || (tmp[0] == 'B' && tmp[2] == 'A')) {
      bool tmp = a;
      a = b;
      b = tmp;
    } else if ((tmp[0] == 'A' && tmp[2] == 'C') ||
               (tmp[0] == 'C' && tmp[2] == 'A')) {
      bool tmp = a;
      a = c;
      c = tmp;
    } else if ((tmp[0] == 'B' && tmp[2] == 'C') ||
               (tmp[0] == 'C' && tmp[2] == 'B')) {
      bool tmp = b;
      b = c;
      c = tmp;
    }
  }
  if (a)
    cout << "A\\n";
  else if (b)
    cout << "B\\n";
  else if (c)
    cout << "C\\n";
}


Error: -11

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int function(char x) {
  cout << x << endl;
  if (x == 'A')
    return 0;
  else if (x == 'B')
    return 1;
  else if (x == 'C')
    return 2;
}
int main() {
  char letter[2];
  bool cup[3] = {true, false, false};
  while (scanf("%c,%c", &letter[0], &letter[1]) != EOF) {
    bool tmp = cup[function(letter[0])];
    cup[function(letter[0])] = cup[function(letter[1])];
    cup[function(letter[1])] = tmp;
  }
  for (int i = 0; i < 3; i++) {
    if (cup[i]) {
      if (i == 0) {
        cout << "A" << endl;
        break;
      } else if (i == 1) {
        cout << "B" << endl;
        break;
      } else if (i == 2) {
        cout << "C" << endl;
      }
    }
  }
}
Problem p00047 (C++) — buggy submission, verdict: 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() {
  string s;
  int in[3] = {0};
  in[0] = 1;
  in[1] = 2;
  in[2] = 3;

  while (cin >> s) {
    char a = s[0];
    char b = s[2];
    if (a == '#')
      break;
    int m[333];
    m['A'] = 0;
    m['B'] = 1;
    m['C'] = 2;

    swap(in[m[a]], in[m[b]]);
  }

  rep(i, 3) {
    if (in[i] == 1) {
      if (i == 0)
        puts("A");
      if (i == 1)
        puts("B");
      if (i == 2)
        puts("C");
    }
  }
}

Error: 0

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() {
  char a, b;
  int in[3] = {0};
  in[0] = 1;
  in[1] = 2;
  in[2] = 3;

  while (scanf("%c,%c", &a, &b) != EOF) {
    if (a == '#')
      break;
    int m[333];
    m['A'] = 0;
    m['B'] = 1;
    m['C'] = 2;

    swap(in[m[a]], in[m[b]]);
  }

  rep(i, 3) {
    if (in[i] == 1) {
      if (i == 0)
        puts("A");
      if (i == 1)
        puts("B");
      if (i == 2)
        puts("C");
    }
  }
}
Problem p00047 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n[3] = {1, 0, 0};
  char k[3];
  while (cin >> k) {
    if (k[0] == 'A') {
      if (k[2] == 'B') {
        swap(n[0], n[1]);
      } else {
        swap(n[0], n[2]);
      }
    }
    if (k[0] == 'B') {
      if (k[2] == 'A') {
        swap(n[1], n[0]);
      } else {
        swap(n[1], n[2]);
      }
    }
    if (k[0] == 'C') {
      if (k[2] == 'A') {
        swap(n[2], n[0]);
      } else {
        swap(n[2], n[1]);
      }
    }
  }
  if (n[0] == 1)
    cout << 'A' << endl;
  else if (n[1] == 1)
    cout << 'B' << endl;
  else
    cout << 'C' << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  char a, b;
  char best = 'A';
  while (scanf("%c,%c") != EOF) {
    if (best == a)
      best = b;
    else if (best == b)
      best = a;
  }
  cout << best << endl;
  return 0;
}
Problem p00047 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int t = 1;
  string S;
  while (cin >> S) {
    if ((S == "B,C") || (S == "C,B")) {
      if (t == 1) {
        t = 1;
      } else if (t == 2) {
        t = 3;
      } else if (t == 3) {
        t = 2;
      }
    } else if ((S == "A,C") || (S == "C,A")) {
      if (t == 1) {
        t = 3;
      } else if (t == 2) {
        t = 2;
      } else if (t == 3) {
        t = 1;
      }
    } else if ((S == "A,B") || (S == "B,A")) {
      if (t == 1) {
        t = 2;
      } else if (t == 2) {
        t = 1;
      } else if (t == 3) {
        t = 3;
      }
    }
  }

  if (t == 1) {
    cout << "A" << endl;
  } else if (t == 2) {
    cout << "B" << endl;
  } else if (t == 3) {
    cout << "C" << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int t = 1;
  string S;
  while (cin >> S, S != "\\0") {
    if ((S == "B,C") || (S == "C,B")) {
      if (t = 1)
        t = 2;
      if (t = 2)
        t = 3;
      if (t = 3)
        t = 2;
    } else if ((S == "A,C") || (S == "C,A")) {
      if (t = 1)
        t = 3;
      if (t = 2)
        t = 2;
      if (t = 3)
        t = 1;
    } else if ((S == "A,B") || (S == "B,A")) {
      if (t = 1)
        t = 2;
      if (t = 2)
        t = 1;
      if (t = 3)
        t = 3;
    }
  }

  if (t = 1)
    cout << "A" << endl;
  if (t = 2)
    cout << "B" << endl;
  if (t = 3)
    cout << "C" << endl;

  return 0;
}
Problem p00047 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<char, int> P;

int main() {
  int a[3]{1};
  string s;
  while (cin >> s) {
    swap(a[s[0] - 'A'], a[s[2] - 'A']);
  }
  rep(k, 3) if (a[k]) printf("%c\\n", k + 'A');
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<char, int> P;

int main() {
  int a[3]{1};
  int i, j;
  while (scanf("%d,%d", &i, &j) != EOF) {
    swap(a[i - 'A'], a[j - 'A']);
  }
  rep(i, 3) if (a[i]) printf("%c\\n", i + 'A');
  return 0;
}
Problem p00047 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  char o1, o2;
  int a = 1, b = 0, c = 0;
  int i = 0;
  while (1) { // scanf("%c,%c", &o1, &o2) != EOF){
    char q;
    if (!(cin >> o1 >> q >> o2))
      break;
    int *p1, *p2;
    if (o1 == '0')
      break;
    else if (o1 == 'A')
      p1 = &a;
    else if (o1 == 'B')
      p1 = &b;
    else if (o1 == 'C')
      p1 = &c;

    if (o2 == 'A')
      p2 = &a;
    else if (o2 == 'B')
      p2 = &b;
    else if (o2 == 'C')
      p2 = &c;

    if (p1 != p2) {
      int s = *p1;
      *p1 = *p2;
      *p2 = s;
    }
    // cout << i << '/'<< a <<  ' ' << b << ' ' << c << endl;
    i++;
  }

  if (a == 1)
    cout << 'A' << endl;
  if (b == 1)
    cout << 'B' << endl;
  if (c == 1)
    cout << 'C' << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  char o1, o2;
  int a = 1, b = 0, c = 0;
  int i = 0;
  while (1) { // scanf("%c,%c", &o1, &o2) != EOF){
    char q;
    cin >> o1 >> q >> o2;
    int *p1, *p2;
    if (o1 == '0')
      break;
    else if (o1 == 'A')
      p1 = &a;
    else if (o1 == 'B')
      p1 = &b;
    else if (o1 == 'C')
      p1 = &c;

    if (o2 == 'A')
      p2 = &a;
    else if (o2 == 'B')
      p2 = &b;
    else if (o2 == 'C')
      p2 = &c;

    if (p1 != p2) {
      int s = *p1;
      *p1 = *p2;
      *p2 = s;
    }
    cout << i << '/' << a << ' ' << b << ' ' << c << endl;
    i++;
  }

  if (a == 1)
    cout << 'A' << endl;
  if (b == 1)
    cout << 'B' << endl;
  if (c == 1)
    cout << 'C' << endl;

  return 0;
}
Problem p00047 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;

int main() {
  int A = 1;
  int B = 0;
  int C = 0;
  string s;
  while (cin >> s) {
    if (s[0] == 'A') {
      if (s[2] == 'B') {
        int tmp;
        tmp = B;
        B = A;
        A = tmp;
      } else if (s[2] == 'C') {
        int tmp;
        tmp = C;
        C = A;
        A = tmp;
      }
    }
    if (s[0] == 'B') {
      if (s[2] == 'A') {
        int tmp;
        tmp = A;
        A = B;
        B = tmp;
      } else if (s[2] == 'C') {
        int tmp;
        tmp = C;
        C = B;
        B = tmp;
      }
    } else if (s[0] == 'C') {
      if (s[2] == 'A') {
        int tmp;
        tmp = A;
        A = C;
        C = tmp;
      } else if (s[2] == 'B') {
        int tmp;
        tmp = B;
        B = C;
        C = tmp;
      }
    }
  }
  if (A == 1) {
    cout << "A" << endl;
  } else if (B == 1) {
    cout << "B" << endl;
  } else if (C == 1) {
    cout << "C" << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

int main() {
  int A = 1;
  int B = 0;
  int C = 0;
  while (true) {
    string s;
    cin >> s;
    if (s[0] == 'A') {
      if (s[2] == 'B') {
        int tmp;
        tmp = B;
        B = A;
        A = tmp;
      } else if (s[2] == 'C') {
        int tmp;
        tmp = C;
        C = A;
        A = tmp;
      }
    }
    if (s[0] == 'B') {
      if (s[2] == 'A') {
        int tmp;
        tmp = A;
        A = B;
        B = tmp;
      } else if (s[2] == 'C') {
        int tmp;
        tmp = C;
        C = B;
        B = tmp;
      }
    } else if (s[0] == 'C') {
      if (s[2] == 'A') {
        int tmp;
        tmp = A;
        A = C;
        C = tmp;
      } else if (s[2] == 'B') {
        int tmp;
        tmp = B;
        B = C;
        C = tmp;
      }
    }
  }
  if (A == 1) {
    cout << "A" << endl;
  } else if (B == 1) {
    cout << "B" << endl;
  } else if (C == 1) {
    cout << "C" << endl;
  }
  return 0;
}
Problem p00047 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;
int main() {
  string str;
  char cup = 'A';
  while (cin >> str) {
    char a, b;
    a = str[0];
    b = str[2];
    if (a == cup) {
      cup = b;
    } else if (b == cup) {
      cup = a;
    }
  }
  cout << cup << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  string str, s1, s2;
  pair<char, int> cup[3];
  cup[0] = make_pair('A', 1);
  cup[1] = make_pair('B', 0);
  cup[2] = make_pair('C', 0);
  while (cin >> str) {
    for (int i = 0; i < 3; i++) {
      if (str[0] == cup[i].first) {
        if (cup[i].second == 0)
          s1 = 'A+i' + '0';
        else
          s2 = 'A+i' + '1';
      }
      if (str[2] == cup[i].first) {
        if (cup[i].second == 0)
          s1 = 'A+i' + '0';
        else
          s2 = 'A+i' + "1";
      }
    }
    if (s2[1] == '0' && s1[1] == '0')
      continue;
    if (s2[1] == '1' && s1[1] == '0') {
      for (int i = 0; i < 3; i++) {
        if (s2[0] == cup[i].first)
          cup[i].second = 1;
        if (s1[0] == cup[i].first)
          cup[i].second = 0;
      }
    } else if (s2[1] == '0' && s1[1] == '1') {
      for (int i = 0; i < 3; i++) {
        if (s2[0] == cup[i].first)
          cup[i].second = 0;
        if (s1[0] == cup[i].first)
          cup[i].second = 1;
      }
    }
  }
  for (int i = 0; i < 3; i++)
    if (cup[i].second == 1)
      cout << cup[i].first << endl;
  return 0;
}
Problem p00047 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

int main() {
  char X, Y, P = 'A';

  while (scanf("%c,%c", &X, &Y) != EOF) {
    if (X == P) {
      P = Y;
    } else if (Y == P) {
      P = X;
    }
  }

  printf("%c\\n", P);

  return 0;
}

Error: TLE

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

int main() {
  char X, Y, P = 'A';

  while (scanf("%c,%c", &X, &Y)) {
    if (X == P) {
      P = Y;
    } else if (Y == P) {
      P = X;
    }
  }

  printf("%c\\n", P);

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

#include <cstdio>
#include <iostream>

using namespace std;

int main(void) {
  char f, t;
  int data[3] = {1, 0, 0};
  while (1) {
    int tmp;
    if (scanf("%c,%c", &f, &t) == EOF)
      break;
    tmp = data[t - 'A'];
    data[t - 'A'] = data[f - 'A'];
    data[f - 'A'] = tmp;
  }
  if (data[0] == 1)
    cout << 'A' << endl;
  else if (data[1] == 1)
    cout << 'B' << endl;
  else
    cout << 'C' << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int main(void) {
  char f, t;
  int data[3] = {1, 0, 0};
  while (1) {
    int tmp;
    if (scanf("%c,%c") == EOF)
      break;
    tmp = data[t - 'A'];
    data[t - 'A'] = data[f - 'A'];
    data[f - 'A'] = tmp;
  }
  if (data[0] == 1)
    cout << 'A' << endl;
  else if (data[1] == 1)
    cout << 'B' << endl;
  else
    cout << 'C' << endl;
  return 0;
}