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

#include <bits/stdc++.h>
#include <ext/algorithm>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

int main() {
  cout << setprecision(6) << fixed;
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  /**************************************************************/

  int n; // The Minkowski’s distance when p = 00
  cin >> n;
  double dbvc[n]; // vcd stands for "difference between vectors components"

  for (int i = 0; i < n; i++)
    cin >> dbvc[i]; // this would be the vector 'x'

  double distance, temp, max_difference = 0;
  for (int i = 0; i < n; i++) {
    cin >> temp; // this would be the vector 'y'
    dbvc[i] = abs(dbvc[i] - temp);
    max_difference = max(max_difference, dbvc[i]);
  }

  for (int j = 0; j < 3; j++) {
    distance = 0;
    for (int i = 0; i < n; i++)
      distance += pow(dbvc[i], j + 1);
    cout << pow(distance, 1.0 / (j + 1)) << endl;
  }
  cout << max_difference << endl;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long arr[10][150];
int main() {
  cout << setprecision(6) << fixed;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  freopen(".in", "r", stdin);
  // entrada
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> arr[0][i];
  for (int i = 0; i < n; i++)
    cin >> arr[1][i];
  // solution
  for (int i = 0; i < n; i++) {
    arr[2][i] = abs(arr[1][i] - arr[0][i]);
  }

  for (int p = 1; p <= 4; p++) {
    long long suma = 0;
    for (int i = 0; i < n; i++) {
      if (p == 4)
        suma = max(suma, arr[2][i]);
      else
        suma += pow(arr[2][i], p);
    }
    double div = 1.0 / p;
    double result = pow(suma, div);
    p == 4 ? cout << 1.0 * suma << "\\n" : cout << result << "\\n";
  }
  return 0;
}
Problem p02382 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;

  vector<int> x(n, 0), y(n, 0);

  for (int i = 0; i < n; ++i)
    cin >> x[i];

  for (int i = 0; i < n; ++i)
    cin >> y[i];

  // ???????????????????????¢(p = 1)
  double md = 0.0;
  double p = 1.0;
  for (int i = 0; i < n; ++i)
    md += pow(abs(x[i] - y[i]), p);
  md = pow(md, 1 / p);

  // ???????????????????????¢(p = 2)
  double ed = 0.0;
  p = 2.0;
  for (int i = 0; i < n; ++i)
    ed += pow(abs(x[i] - y[i]), p);
  ed = pow(ed, 1 / p);

  // p = 3?????¨???
  double td = 0.0;
  p = 3.0;
  for (int i = 0; i < n; ++i)
    td += pow(abs(x[i] - y[i]), p);
  td = pow(td, 1 / p);

  // ?????§????????§????????¢(p = ???)
  double cd = 0.0;
  for (int i = 0; i < n; ++i)
    if (abs(x[i] - y[i]) > cd)
      cd = abs(x[i] - y[i]);

  cout << setprecision(16) << md << endl;
  cout << ed << endl;
  cout << td << endl;
  cout << cd << endl;

  return 0;
}

Error: WA

Fixed submission:

#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;

  vector<int> x(3, 0), y(3, 0);

  for (int i = 0; i < n; ++i)
    cin >> x[i];

  for (int i = 0; i < n; ++i)
    cin >> y[i];

  // ???????????????????????¢(p = 1)
  double md = 0.0;
  double p = 1.0;
  for (int i = 0; i < n; ++i)
    md += pow(abs(x[i] - y[i]), p);
  md = pow(md, 1 / p);

  // ???????????????????????¢(p = 2)
  double ed = 0.0;
  p = 2.0;
  for (int i = 0; i < n; ++i)
    ed += pow(abs(x[i] - y[i]), p);
  ed = pow(ed, 1 / p);

  // p = 3?????¨???
  double td = 0.0;
  p = 3.0;
  for (int i = 0; i < n; ++i)
    td += pow(abs(x[i] - y[i]), p);
  td = pow(td, 1 / p);

  // ?????§????????§????????¢(p = ???)
  double cd = 0.0;
  for (int i = 0; i < n; ++i)
    if (abs(x[i] - y[i]) > cd)
      cd = abs(x[i] - y[i]);

  cout << setprecision(16) << md << endl;
  cout << ed << endl;
  cout << td << endl;
  cout << cd << endl;

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

#include <cfloat>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<double> x(n), y(n), d(4);

  for (auto &xi : x)
    cin >> xi;
  for (auto &yi : y)
    cin >> yi;

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < n; j++)
      d[i] += pow(abs(x[j] - y[j]), i + 1);
    d[i] = pow(d[i], 1.0 / (i + 1));
  }

  d[3] = DBL_MIN;
  for (int i = 0; i < n; i++)
    d[3] = max(d[3], abs(x[i] - y[i]));

  cout << fixed << setprecision(8);
  for (auto &di : d)
    cout << di << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;

int main() {
  int n;
  cout << fixed << setprecision(8);
  while (cin >> n, n) {
    double sum = 0, Sum = 0, s;
    for (int i = n; i--;) {
      cin >> s;
      sum += s;
      Sum += s * s;
    }
    cout << sqrt(Sum / n - pow(sum / n, 2)) << endl;
  }

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

#include <cmath>
#include <cstdlib>
#include <iostream>

using namespace std;

int main() {

  int n;
  cin >> n;

  int *X;
  int *Y;

  X = new int[n];
  Y = new int[n];

  for (int i = 0; i < n; i++) {
    cin >> X[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> Y[i];
  }

  for (int i = 0; i < 3; i++) {
    double sum;
    sum = 0;
    for (int j = 0; j < n; j++) {
      sum += pow(abs(X[j] - Y[j]), i + 1);
    }
    cout << fixed << pow(sum, (1.0 / (i + 1.0))) << endl;
  }

  double max;
  max = 0;
  for (int i = 0; i < n; i++) {
    if (max < abs(X[i] - Y[i])) {
      max = abs(X[i] - Y[i]);
    }
  }
  cout << fixed << max << endl;

  delete[] X;
  delete[] Y;
}

Error: -11

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

int main() {

  int n;
  cin >> n;

  int *X;
  int *Y;

  X = new int[n];
  Y = new int[n];

  for (int i = 0; i < n; i++) {
    cin >> X[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> Y[i];
  }

  double sum;

  for (int i = 0; i < 4; i++) {
    sum = 0;
    for (int j = 0; i < n; j++) {
      sum += pow((X[j] - Y[j]), i + 1);
    }
    cout << fixed << pow(sum, 1 / (i + 1)) << endl;
  }
}
Problem p02382 (C++) — buggy submission, verdict: Runtime Error

#include <math.h>
#include <stdio.h>

int main() {
  int n, x[100], y[100];
  int i;
  double ma = 0, eu = 0, m3 = 0, ch = 0, di;
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d", &x[i]);
  for (i = 0; i < n; i++)
    scanf("%d", &y[i]);
  for (i = 0; i < n; i++) {
    di = fabs(x[i] - y[i]);
    ma += di;
    eu += di * di;
    m3 += di * di * di;
    if (ch < di)
      ch = di;
  }
  printf("%f %f %f %f\\n", ma, sqrt(eu), pow(m3, 1. / 3), ch);
}

Error: WA

Fixed submission:

#include <math.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
  int n, *x, *y;
  int i;
  double ma = 0, eu = 0, m3 = 0, ch = 0, di;
  x = (int *)calloc(n, sizeof(int));
  y = (int *)calloc(n, sizeof(int));
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d", x + i);
  for (i = 0; i < n; i++)
    scanf("%d", y + i);
  for (i = 0; i < n; i++) {
    di = abs(x[i] - y[i]);
    ma += di;
    eu += pow(di, 2);
    m3 += pow(di, 3);
    if (ch < di)
      ch = di;
  }
  printf("%f %f %f %f\\n", ma, sqrt(eu), pow(m3, 1. / 3), ch);
}
Problem p02382 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int n;
double x[100], y[100];

double distance(double p) {
  double sum = 0;
  for (int i = 0; i < n; i++) {
    double w = abs(x[i] - y[i]);
    sum += pow(w, p);
  }
  return pow(sum, 1.0 / p);
}

int main() {
  cout << fixed << setprecision(12);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> y[i];
  }
  cout << distance(1) << endl;
  cout << distance(2) << endl;
  cout << distance(3) << endl;
  double mx = 0;
  for (int i = 0; i < n; i++) {
    mx = max(mx, abs(x[i] - y[i]));
  }
  cout << mx << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int n;
double x[100], y[100];

double distance(double p) {
  double sum = 0;
  for (int i = 0; i < n; i++) {
    double w = abs(x[i] - y[i]);
    sum += pow(w, p);
  }
  return pow(sum, 1.0 / p);
}

int main() {
  cout << fixed << setprecision(12);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> y[i];
  }
  cout << distance(1) << endl;
  cout << distance(2) << endl;
  cout << distance(3) << endl;
  double mx = 0;
  for (int i = 0; i, n; i++) {
    mx = max(mx, abs(x[i] - y[i]));
  }
  cout << mx << endl;
  return 0;
}
Problem p02383 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int huru(string x, int d1, int d2, int d3, int d4, int d5, int d6) {
  int a, b;
  for (int i = 0; i < x.size(); i++) {
    if (x.at(i) == 'E') {
      a = d3;
      d3 = d1;
      d1 = d4;
      d4 = d6;
      d6 = a;
    }
    if (x.at(i) == 'S') {
      a = d2;
      d2 = d1;
      d1 = d5;
      d5 = d6;
      d6 = a;
    }
    if (x.at(i) == 'W') {
      a = d4;
      d4 = d1;
      d1 = d3;
      d3 = d6;
      d6 = a;
    }
    if (x.at(i) == 'N') {
      a = d5;
      d5 = d1;
      b = d6;
      d6 = a;
      a = d2;
      d2 = b;
      d1 = a;
    }
    a = 0;
  }
  return d1;
}
int main() {
  int s1, s2, s3, s4, s5, s6;
  cin >> s1 >> s2 >> s3 >> s4 >> s5 >> s6;
  string x;
  cin >> x;

  cout << huru(x, s1, s2, s3, s4, s5, s6) << endl;
  return 0;
}


Error: -6
free(): invalid pointer


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
class dice {
public:
  int d1;
  int d2;
  int d3;
  int d4;
  int d5;
  int d6;
  int kaisi(int s1, int s2, int s3, int s4, int s5, int s6);
  string huru(string x);
};
int dice::kaisi(int s1, int s2, int s3, int s4, int s5, int s6) {
  d1 = s1;
  d2 = s2;
  d3 = s3;
  d4 = s4;
  d5 = s5;
  d6 = s6;
}
string dice::huru(string x) {
  int a, b, c, d, e, f;
  for (int i = 0; i < x.size(); i++) {
    if (x.at(i) == 'E') {
      a = d3;
      d3 = d1;
      d1 = d4;
      d4 = d6;
      d6 = a;
    }
    if (x.at(i) == 'S') {
      a = d2;
      d2 = d1;
      d1 = d5;
      d5 = d6;
      d6 = a;
    }
    if (x.at(i) == 'W') {
      a = d4;
      d4 = d1;
      d1 = d3;
      d3 = d6;
      d6 = a;
    }
    if (x.at(i) == 'N') {
      a = d5;
      d5 = d1;
      d1 = d2;
      d2 = d6;
      d2 = a;
    }
  }
}
int main() {
  int s1, s2, s3, s4, s5, s6;
  cin >> s1 >> s2 >> s3 >> s4 >> s5 >> s6;
  string x;
  cin >> x;
  dice iti;
  iti.kaisi(s1, s2, s3, s4, s5, s6);
  iti.huru(x);
  cout << iti.d1 << endl;
  return 0;
}
Problem p02383 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

class Dice {
public:
  int top, face[6];
  void East() {
    top = face[0];
    face[0] = face[3];
    face[3] = face[5];
    face[5] = face[2];
    face[2] = top;
  }
  void West() {
    top = face[0];
    face[0] = face[2];
    face[2] = face[5];
    face[5] = face[3];
    face[3] = top;
  }
  void North() {
    top = face[0];
    face[0] = face[1];
    face[1] = face[5];
    face[5] = face[4];
    face[4] = top;
  }
  void South() {
    top = face[0];
    face[0] = face[4];
    face[4] = face[5];
    face[5] = face[1];
    face[1] = top;
  }
};

int main() {
  int i;
  string o;
  Dice dice;
  for (i = 0; i < 6; i++)
    cin >> dice.face[i];
  cin >> o;
  for (i = 0; i < o.length(); i++) {
    switch (o[i]) {
    case 'E':
      dice.East();
      break;
    case 'W':
      dice.West();
      break;
    case 'N':
      dice.North();
      break;
    case 'S':
      dice.South();
      break;
    }
  }
  cout << dice.face[0] << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

class Dice {
public:
  int n1, n2, n3, n4, n5, n6;

  void East() {
    int t = n1;
    n1 = n4;
    n4 = n6;
    n6 = n3;
    n3 = t;
  }

  void West() {
    int t = n1;
    n1 = n3;
    n3 = n6;
    n6 = n4;
    n4 = t;
  }

  void South() {
    int t = n1;
    n1 = n5;
    n5 = n6;
    n6 = n2;
    n2 = t;
  }

  void North() {
    int t = n1;
    n1 = n2;
    n2 = n6;
    n6 = n5;
    n5 = t;
  }
};

int main() {
  Dice dice;
  int n1, n2, n3, n4, n5, n6;
  char ch;
  cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;

  dice.n1 = n1;
  dice.n2 = n2;
  dice.n3 = n3;
  dice.n4 = n4;
  dice.n5 = n5;
  dice.n6 = n6;

  cin >> ch;
  while (1) {
    if (ch == 'E') {
      dice.East();
    } else if (ch == 'W') {
      dice.West();
    } else if (ch == 'S') {
      dice.South();
    } else if (ch == 'N') {
      dice.North();
    }
  }
  cout << dice.n1 << endl;
  return 0;
}
Problem p02383 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

struct Dice {
  vector<int> faces;

  Dice(vector<int> &f) : faces(f) {}

  int top() { return faces.front(); }

  void roll(char direction) {
    int tmp;
    switch (direction) {
    case 'E': // 1,4,6,3 -> 4,6,3,1
      tmp = faces[0];
      faces[0] = faces[3];
      faces[3] = faces[5];
      faces[5] = faces[2];
      faces[2] = tmp;
      break;
    case 'N': // 1,2,6,5 -> 2,6,5,1
      tmp = faces[0];
      faces[0] = faces[1];
      faces[1] = faces[5];
      faces[5] = faces[4];
      faces[4] = tmp;
      break;
    case 'S': // 1,5,6,2 -> 5,6,2,1
      tmp = faces[0];
      faces[0] = faces[4];
      faces[4] = faces[5];
      faces[5] = faces[1];
      faces[1] = tmp;
      break;
    case 'W': // 1,3,6,4 -> 3,6,4,1
      tmp = faces[0];
      faces[0] = faces[2];
      faces[2] = faces[5];
      faces[5] = faces[3];
      faces[3] = tmp;
      break;
    }
  }
};

int main() {
  vector<int> faces;
  for (int i = 0; i < 6; ++i) {
    int x;
    cin >> x;
    faces.push_back(x);
  }

  Dice dice(faces);
  string s;
  cin >> s;

  // cerr << s << endl;
  for (string::iterator it = s.begin(); it != s.end(); ++it) {
    dice.roll(*it);
    // cerr << *it << "->" << dice.top() << endl;
  }
  cout << dice.top() << endl;

  return 0;
}

Error: 0
S->16
E->8


Fixed submission:

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

using namespace std;

struct Dice {
  vector<int> faces;

  Dice(vector<int> &f) : faces(f) {}

  int top() { return faces.front(); }

  void roll(char direction) {
    int tmp;
    switch (direction) {
    case 'E': // 1,4,6,3 -> 4,6,3,1
      tmp = faces[0];
      faces[0] = faces[3];
      faces[3] = faces[5];
      faces[5] = faces[2];
      faces[2] = tmp;
      break;
    case 'N': // 1,2,6,5 -> 2,6,5,1
      tmp = faces[0];
      faces[0] = faces[1];
      faces[1] = faces[5];
      faces[5] = faces[4];
      faces[4] = tmp;
      break;
    case 'S': // 1,5,6,2 -> 5,6,2,1
      tmp = faces[0];
      faces[0] = faces[4];
      faces[4] = faces[5];
      faces[5] = faces[1];
      faces[1] = tmp;
      break;
    case 'W': // 1,3,6,4 -> 3,6,4,1
      tmp = faces[0];
      faces[0] = faces[2];
      faces[2] = faces[5];
      faces[5] = faces[3];
      faces[3] = tmp;
      break;
    }
  }
};

int main() {
  vector<int> faces;
  for (int i = 0; i < 6; ++i) {
    int x;
    cin >> x;
    faces.push_back(x);
  }

  Dice dice(faces);
  string s;
  cin >> s;

  // cerr << s << endl;
  for (string::iterator it = s.begin(); it != s.end(); ++it) {
    dice.roll(*it);
    cerr << *it << "->" << dice.top() << endl;
  }
  cout << dice.top() << endl;

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

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

class Dice {
public:
  int face[6];

  Dice() {}
  void direction(char ch) {
    if (ch == 'E')
      rotate(0, 2, 5, 3);
    if (ch == 'W')
      rotate(0, 3, 5, 2);
    if (ch == 'S')
      rotate(0, 1, 5, 4);
    if (ch == 'N')
      rotate(0, 4, 5, 1);
  }

  void rotate(int a, int b, int c, int d) {
    int temp[4] = {};

    temp[0] = face[a];
    temp[1] = face[b];
    temp[2] = face[c];
    temp[3] = face[d];
    // ダイス入れ替え
    face[a] = temp[3];
    face[b] = temp[0];
    face[c] = temp[1];
    face[d] = temp[2];
  }
};

int main() {
  Dice dice1;
  string D;

  for (int i = 0; i < 6; i++) {
    cin >> dice1.face[i];
  }
  cin >> D;
  for (int j = 0; j < D.size(); j++) {
    dice1.direction(D[j]);
  }
  cout << dice1.face[0] << endl;
  return 0;
}

Error: -11

Fixed submission:

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

class Dice {
public:
  int face[7];

  Dice(int faceface[7]) { face[7] = faceface[7]; }

  void move(string D) {
    int temp[4] = {};
    if (D == "N") {
      temp[0] = face[1];
      temp[1] = face[2];
      temp[2] = face[6];
      temp[3] = face[5];
      // ダイス入れ替え
      face[1] = temp[1];
      face[2] = temp[2];
      face[6] = temp[3];
      face[5] = temp[0];
    }
    if (D == "E") {
      temp[0] = face[1];
      temp[1] = face[4];
      temp[2] = face[6];
      temp[3] = face[3];
      // ダイス入れ替え
      face[1] = temp[1];
      face[4] = temp[2];
      face[6] = temp[3];
      face[3] = temp[0];
    }
    if (D == "S") {
      temp[0] = face[1];
      temp[1] = face[5];
      temp[2] = face[6];
      temp[3] = face[2];
      // ダイス入れ替え
      face[1] = temp[1];
      face[5] = temp[2];
      face[6] = temp[3];
      face[2] = temp[0];
    }
    if (D == "W") {
      temp[0] = face[1];
      temp[1] = face[3];
      temp[2] = face[6];
      temp[3] = face[4];
      // ダイス入れ替え
      face[1] = temp[1];
      face[3] = temp[2];
      face[6] = temp[3];
      face[4] = temp[0];
    }
  }
};

int main() {
  Dice d(0);
  string D;

  for (int i = 1; i < 7; i++) {
    cin >> d.face[i];
  }
  while (cin >> D) {
    d.move(D);
  }
  cout << d.face[1] << endl;
  return 0;
}
Problem p02383 (C++) — buggy submission, verdict: Time Limit Exceeded

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

class dice {
public:
  int d[7];

  dice() { //??????????????????????????????
  }

  void east() {
    d[0] = d[1], d[1] = d[4], d[4] = d[6], d[6] = d[3], d[3] = d[0];
  }

  void west() {
    d[0] = d[4], d[4] = d[1], d[1] = d[3], d[3] = d[6], d[6] = d[0];
  }

  void north() {
    d[0] = d[5], d[5] = d[1], d[1] = d[2], d[2] = d[6], d[6] = d[0];
  }

  void south() {
    d[0] = d[2], d[2] = d[1], d[1] = d[5], d[5] = d[6], d[6] = d[0];
  }
};

int main() {
  string n;
  dice A;
  for (int i = 1; i < 7; i++) {
    cin >> A.d[i];
  }
  cin >> n;

  for (int i = 0; i < n.size(); i++) {

    if (n[i] == 'E')
      A.east();
    else if (n[i] == 'W')
      A.west();
    else if (n[i] == 'N')
      A.north();
    else if (n[i] == 'S')
      A.south();
  }

  cout << A.d[1] << endl;

  // for(int i=0; i<7; i++){ //test=ok
  //    cout << A.d[i] << " ";
  // }
  // cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

class dice {
public:
  int d[7];

  dice() { //??????????????????????????????
  }

  void east() {
    d[0] = d[1], d[1] = d[4], d[4] = d[6], d[6] = d[3], d[3] = d[0];
  }

  void west() {
    d[0] = d[4], d[4] = d[1], d[1] = d[3], d[3] = d[6], d[6] = d[0];
  }

  void north() {
    d[0] = d[5], d[5] = d[1], d[1] = d[2], d[2] = d[6], d[6] = d[0];
  }

  void south() {
    d[0] = d[2], d[2] = d[1], d[1] = d[5], d[5] = d[6], d[6] = d[0];
  }
};

int main() {
  char n;
  dice A;
  for (int i = 1; i < 7; i++) {
    cin >> A.d[i];
  }

  while (1) {
    cin >> n;
    // if(n=='A')break; //test??§????????????????????¨
    if (n == '\\n')
      break; // cygwin??°?¢??????¨???????????????
    if (n == 'E')
      A.east();
    else if (n == 'W')
      A.west();
    else if (n == 'N')
      A.north();
    else if (n == 'S')
      A.south();
  }

  cout << A.d[1] << endl;

  // for(int i=0; i<7; i++){ //test=ok
  //    cout << A.d[i] << " ";
  // }
  // cout << endl;

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

#include <stdio.h>
int i, N[7], T, F, R, t;
char S[105];
int main() {
  for (i = 1; i <= 6; i++)
    scanf("%d", N + i);
  gets(S);
  gets(S);
  for (T = 1, F = 2, R = 3, i = 0; S[i]; i++) {
    switch (S[i]) {
    case 'N':
      t = T, T = F, F = 7 - t;
      break;
    case 'E':
      t = R, R = T, T = 7 - t;
      break;
    case 'S':
      t = F, F = T, T = 7 - t;
      break;
    case 'W':
      t = T, T = R, R = 7 - t;
      break;
    }
  }
  printf("%d\\n", N[T]);
  return 0;
}

Error: -11

Fixed submission:

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct dice {
  int num[6];
};

int main() {
  struct dice one;
  int i;
  for (i = 0; i < 6; i++) {
    scanf("%d", &one.num[i]);
  }
  char *cmd;
  scanf("%s", cmd);
  for (i = 0; i < strlen(cmd); i++) {
    int tmp1, tmp2;
    switch (cmd[i]) {
    case 'N': {
      tmp1 = one.num[0];
      one.num[0] = one.num[1];
      one.num[1] = one.num[5];
      one.num[4] = tmp1;
    } break;
    case 'E': {
      tmp1 = one.num[0];
      tmp2 = one.num[3];
      one.num[0] = one.num[3];
      one.num[2] = tmp1;
      one.num[3] = one.num[5];
      one.num[5] = tmp2;
    } break;
    case 'W': {
      tmp1 = one.num[0];
      tmp2 = one.num[3];
      one.num[2] = one.num[5];
      one.num[3] = tmp1;
      one.num[5] = tmp2;
    } break;
    case 'S': {
      tmp1 = one.num[0];
      tmp2 = one.num[5];
      one.num[0] = one.num[4];
      one.num[5] = one.num[1];
      one.num[1] = tmp1;
      one.num[4] = tmp2;
    } break;
    }
  }
  printf("%d\\n", one.num[0]);
  printf("%d\\n", strlen(cmd));

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

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

class dice {
private:
  int me[6];

public:
  int set();
  int roll(char c);
  int show();
};

int dice::set() {
  int i;

  for (i = 0; i < 6; i++)
    cin >> me[i];

  return 0;
}

int dice::roll(char c) {
  int temp;
  if (c == 'S') {
    temp = me[0];
    me[0] = me[4];
    me[4] = me[5];
    me[5] = me[1];
    me[1] = temp;
  } else if (c == 'N') {
    temp = me[0];
    me[0] = me[1];
    me[1] = me[5];
    me[5] = me[4];
    me[4] = temp;
  } else if (c == 'W') {
    temp = me[0];
    me[0] = me[2];
    me[2] = me[5];
    me[5] = me[3];
    me[3] = temp;
  } else if (c == 'E') {
    temp = me[0];
    me[0] = me[3];
    me[3] = me[5];
    me[5] = me[2];
    me[2] = temp;
  }

  return 0;
}

int dice::show() {

  cout << me[0] << endl;
  return 0;
}

int main() {
  dice d;
  string c;
  int i;

  d.set();

  cin >> c;

  for (i = 0; i < c.length(); i++)
    d.roll(c[i]);

  d.show();

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

class dice {
private:
  int me[6];

public:
  int set();
  int roll(char c);
  int show();
};

int dice::set() {
  int i;

  for (i = 0; i < 6; i++)
    cin >> me[i];

  return 0;
}

int dice::roll(char c) {
  int temp;
  if (c == 'S') {
    temp = me[0];
    me[0] = me[4];
    me[4] = me[5];
    me[5] = me[1];
    me[1] = temp;
  } else if (c == 'N') {
    temp = me[0];
    me[0] = me[1];
    me[1] = me[5];
    me[5] = me[4];
    me[4] = temp;
  } else if (c == 'W') {
    temp = me[0];
    me[0] = me[2];
    me[2] = me[5];
    me[5] = me[3];
    me[3] = temp;
  } else if (c == 'E') {
    temp = me[0];
    me[0] = me[3];
    me[3] = me[5];
    me[5] = me[2];
    me[2] = temp;
  }

  return 0;
}

int dice::show() {

  cout << me[0] << endl;
  return 0;
}

int main() {
  dice d;
  char c;

  d.set();

  while (1) {
    cin >> c;

    if (c == '\\n')
      break;

    d.roll(c);
  }

  d.show();

  return 0;
}