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

#include <bits/stdc++.h>
#define dum(x) cout << #x << '=' << x << endl
using namespace std;

int main() {
  int w, n;
  cin >> w >> n;
  vector<pair<int, int>> vp(w);
  for (int i = 0; i < w; i++) {
    vp.at(i) = make_pair(i + 1, i + 1);
  }

  for (int i = 0; i < n; i++) {
    int a, b;
    char c;
    cin >> a >> c >> b;
    int tmp;
    for (int i = 0; i < w; i++) {
      if (vp.at(i).second == a) {
        vp.at(i).second = b;
        tmp = i;
      }
    }
    for (int i = 0; i < w; i++) {
      if (i == tmp)
        continue;
      if (vp.at(i).second == b) {
        vp.at(i).second = a;
      }
    }
  }

  for (int i = 0; i < w; i++) {
    swap(vp.at(i).first, vp.at(i).second);
  }

  sort(vp.begin(), vp.end());
  for (int i = 0; i < w; i++) {
    cout << vp.at(i).second << endl;
    ;
  }
}


Error: 0

Fixed submission:

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

int main() {
  int w, n;
  cin >> w >> n;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    a.push_back(s.at(0) - '0');
    a.push_back(s.at(2) - '0');
  }
  vector<int> ans(w);
  for (int i = 1; i <= w; i++) {
    int tmp = i;
    for (int j = 0; j < a.size(); j += 2) {
      if (tmp == a.at(j)) {
        tmp = a.at(j + 1);
        continue;
      }
      if (tmp == a.at(j + 1)) {
        tmp = a.at(j);
        continue;
      }
    }
    ans.at(tmp - 1) = i;
  }
  for (int i = 0; i < w; i++) {
    cout << ans.at(i) << endl;
  }
}
Problem p00011 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string sa, sb;
  int w, n, a, b, c;
  cin >> w >> n;
  int num[w];
  for (int i = 0; i < w; i++)
    num[i] = i + 1;
  for (; n > 0; n--) {
    getline(cin, sa, ',');
    getline(cin, sb, '\\n');
    a = atoi(sa.c_str()) - 1;
    b = atoi(sb.c_str()) - 1;
    c = num[a];
    num[a] = num[b];
    num[b] = c;
  }
  for (int i = 0; i < w; i++)
    cout << num[i] << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  string sa, sb;
  int w, n, a, b, c;
  int num[w];
  cin >> w >> n;
  for (int i = 0; i < w; i++)
    num[i] = i + 1;
  for (; n > 0; n--) {
    getline(cin, sa, ',');
    getline(cin, sb, '\\n');
    a = atoi(sa.c_str()) - 1;
    b = atoi(sb.c_str()) - 1;
    c = num[a];
    num[a] = num[b];
    num[b] = c;
  }
  for (int i = 0; i < w; i++)
    cout << num[i] << endl;
  return 0;
}
Problem p00011 (C++) — buggy submission, verdict: Runtime Error

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define EPS 1.0e-8
#define MAX_N 100
typedef pair<int, int> Pii;
typedef pair<int, int> Pis;
const double PI = acos(-1);

int main() {
  int w, n;
  int stage[30];
  int a, b;
  cin >> w >> n;
  rep(i, w) stage[i] = i + 1;

  rep(i, n) {
    scanf("%d,%d", &a, &b);
    stage[a - 1] ^= stage[b - 1];
    stage[b - 1] ^= stage[a - 1];
    stage[a - 1] ^= stage[b - 1];
  }

  rep(i, w) cout << stage[i] << endl;
}

Error: 0

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define EPS 1.0e-8
#define MAX_N 100
typedef pair<int, int> Pii;
typedef pair<int, int> Pis;
const double PI = acos(-1);

int main() {
  int w, n;
  int stage[w];
  int a, b;
  cin >> w >> n;
  rep(i, w) stage[i] = i + 1;

  rep(i, n) {
    scanf("%d,%d", &a, &b);
    stage[a - 1] ^= stage[b - 1];
    stage[b - 1] ^= stage[a - 1];
    stage[a - 1] ^= stage[b - 1];
  }

  rep(i, w) cout << stage[i] << endl;
}
Problem p00011 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

int listen_lineCount();
void listen_path(int &from, int &to);

class Lots {
private:
  int *start_goal;
  int verLineNum;

public:
  Lots(const int lineCount);
  ~Lots();

  void draw_line(const int from, const int to);
  void echo_goalNums();
};

//-------------------------main--------------------------------

int main() {
  int ver_lineCount = listen_lineCount();
  Lots inst_lot = Lots(ver_lineCount);

  int hor_lineCount = listen_lineCount();

  int from, to;
  for (int roop = 0; roop < hor_lineCount; roop++) {
    listen_path(from, to);
    inst_lot.draw_line(from, to);
  }

  inst_lot.echo_goalNums();
  return 0;
}

//--------------------------------------------------------------

Lots::Lots(const int lineCount) {
  verLineNum = lineCount;
  start_goal = new int[lineCount + 1];

  for (int roop = 1; roop <= lineCount; roop++) {
    start_goal[roop] = roop;
  }
}

Lots::~Lots() { delete[] start_goal; }

void Lots::draw_line(const int from, const int to) {
  int swap = start_goal[from];
  start_goal[from] = start_goal[to];
  start_goal[to] = swap;
}

void Lots::echo_goalNums() {
  using namespace std;

  for (int roop = 1; roop <= verLineNum; roop++) {
    cout << start_goal[roop] << endl;
  }
}

int listen_lineCount() {
  using namespace std;

  int lineCount;
  cin >> lineCount;

  return lineCount;
}

void listen_path(int &from, int &to) {
  using namespace std;

  char delim; // カンマ区切り

  cin >> from >> delim >> to;
}

Error: 0

Fixed submission:

#include <iostream>

int listen_lineCount();
void listen_path(int &from, int &to);

class Lots {
private:
  int *start_goal;
  int verLineNum;

public:
  Lots(const int lineCount);
  ~Lots();

  void draw_line(const int from, const int to);
  void echo_goalNums();
};

//-------------------------main--------------------------------

int main() {
  int ver_lineCount = listen_lineCount();
  Lots *inst_lot;
  inst_lot = new Lots(ver_lineCount);

  int hor_lineCount = listen_lineCount();

  int from, to;
  for (int roop = 0; roop < hor_lineCount; roop++) {
    listen_path(from, to);
    inst_lot->draw_line(from, to);
  }

  inst_lot->echo_goalNums();

  delete inst_lot;
  return 0;
}

//--------------------------------------------------------------

Lots::Lots(const int lineCount) {
  verLineNum = lineCount;
  start_goal = new int(lineCount + 1);

  for (int roop = 1; roop <= lineCount; roop++) {
    start_goal[roop] = roop;
  }
}

Lots::~Lots() { delete[] start_goal; }

void Lots::draw_line(const int from, const int to) {
  int swap = start_goal[from];
  start_goal[from] = start_goal[to];
  start_goal[to] = swap;
}

void Lots::echo_goalNums() {
  using namespace std;

  for (int roop = 1; roop <= verLineNum; roop++) {
    cout << start_goal[roop] << endl;
  }
}

int listen_lineCount() {
  using namespace std;

  int lineCount;
  cin >> lineCount;

  return lineCount;
}

void listen_path(int &from, int &to) {
  using namespace std;

  char delim; // カンマ区切り

  cin >> from >> delim >> to;
}
Problem p00011 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int i, temp;
  int w, n, ai, bi;

  cin >> w;
  cin >> n;

  vector<int> amida;

  // initialize
  for (i = 0; i < w; i++) {
    amida.push_back(i + 1);
  }

  for (i = 0; i < n; i++) {
    scanf("%d,%d", &ai, &bi);

    // swap
    temp = amida.at(ai - 1);
    amida.at(ai - 1) = amida.at(bi - 1);
    amida.at(bi - 1) = temp;
  }

  for (i = 0; i < w; i++) {
    cout << amida.at(i) << endl;
  }

  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 1631744127) >= this->size() (which is 5)


Fixed submission:

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

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

  int i, temp;
  int w, n, ai, bi;

  cin >> w;
  cin >> n;

  vector<int> amida;

  // initialize
  for (i = 0; i < w; i++) {
    amida.push_back(i + 1);
  }

  for (i = 0; i < n; i++) {
    scanf("%d,%d", &ai, &bi);

    // swap
    temp = amida.at(ai - 1);
    amida.at(ai - 1) = amida.at(bi - 1);
    amida.at(bi - 1) = temp;
  }

  for (i = 0; i < w; i++) {
    cout << amida.at(i) << endl;
  }

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

#include <iostream>
#include <stdio.h>
#include <vector>
int main() {
  int w;
  std::cin >> w;
  std::vector<int> a(w + 1);
  for (int i = 1; i <= w; i++)
    a[i] = i;
  int n;
  std::cin >> n;
  while (n > 0) {
    int b, c;
    scanf("%d,%d", &b, &c);
    // std::cin>>b>>c;
    int d = a[b];
    a[b] = a[c];
    a[c] = d;
    n--;
  }
  for (int i = 1; i <= w; i++)
    std::cout << a[i] << std::endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <vector>
int main() {
  int w;
  std::cin >> w;
  std::vector<int> a(w);
  for (int i = 1; i <= w; i++)
    a[i] = i;
  int n;
  std::cin >> n;
  while (n > 0) {
    int b, c;
    scanf("%d,%d", &b, &c);
    // std::cin>>b>>c;
    int d = a[b];
    a[b] = a[c];
    a[c] = d;
    n--;
  }
  for (int i = 1; i <= w; i++)
    std::cout << a[i] << std::endl;
  return 0;
}
Problem p00011 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <stdio.h>

#define MAX 30
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define rept(i, a, b) for (int i = (a); i <= (b); ++i)

int main() {
  int w, n;
  int num[MAX];
  int a, b;
  std::cin >> w >> n;
  rep(i, MAX) num[i] = i + 1;
  rep(i, n) {
    scanf("%d,%d", &a, &b);
    std::swap(num[a - 1], num[b - 1]);
  }
  rep(i, w) std::cout << num[i] << std::endl;
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>

#define MAX 30
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define rept(i, a, b) for (int i = (a); i <= (b); ++i)

int main() {
  int w, n;
  int num[MAX];
  int a, b;
  rep(i, n) num[i] = i + 1;
  std::cin >> w >> n;
  rep(i, n) {
    scanf("%d,%d", &a, &b);
    std::swap(num[a - 1], num[b - 1]);
  }
  rep(i, w) std::cout << num[i] << std::endl;
  return 0;
}
Problem p00011 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int w, n;
  int p;
  cin >> w >> n;
  int c[w];
  int a[n];
  int b[n];
  int j = 0;
  int j2 = 0;
  char q[n];
  for (int i = 0; i < w; i++)
    c[i] = i + 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> q[n] >> b[i];
  }
  for (int i = 0; i < n; i++) {
    j = a[i] - 1;
    j2 = b[i] - 1;
    p = c[j];
    c[j] = c[j2];
    c[j2] = p;
  }
  for (int i = 0; i < w; i++)
    cout << c[i] << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int w, n;
  int p;
  cin >> w >> n;
  int c[w];
  int a[n];
  int b[n];
  int j, j2;
  for (int i = 0; i < w; i++)
    c[i] = i + 1;
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  for (int i = 0; i < n; i++) {
    j = a[i] - 1;
    j2 = b[i] - 1;
    p = c[j];
    c[j] = c[j2];
    c[j2] = p;
  }
  for (int i = 0; i < w; i++)
    cout << c[i] << endl;
  return 0;
}
Problem p00011 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int w, n;
  int u[30];
  cin >> w >> n;
  for (int i = 0; i < w; i++) {
    u[i] = i + 1;
  }
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d,%d", &a, &b);
    swap(u[a - 1], u[b - 1]);
  }
  for (int i = 0; i < w; i++) {
    cout << u[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  vector<int> v;
  vector<int>::iterator pv = v.begin();
  int w, n;
  scanf("%d,%d", &w, &n);
  for (int i = 0; i < w; i++) {
    v.push_back(i + 1);
  }
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d,%d", &a, &b);
    swap(v[a - 1], v[b - 1]);
  }
  for (int i = 0; i < w; i++) {
    cout << *pv << endl;
    pv++;
  }
  return 0;
}
Problem p00011 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main(void) {
  int i, tate, yoko, a, b, temp;
  int array[] = {1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15,
                 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30};

  scanf("%d %d", &tate, &yoko);

  for (i = 0; i < yoko; i++) {
    scanf("%d,%d", &a, &b);
    a--;             // for array index
    b--;             // for array index
    temp = array[a]; // swap values
    array[a] = array[b];
    array[b] = temp;
  }

  for (i = 0; i < tate; i++) {
    printf("%d\\n", array[i]);
  }

  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main() {
  int tate, yoko, bou[30][2], j, x,
      kekka[] = {1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15,
                 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30},
      i = 0;
  scanf("%d %d", &tate, &yoko);
  for (j = 0; j < yoko; j++) {
    scanf("%d %d", &bou[j][1], &bou[j][2]);
  }
  for (i = 1; i < tate + 1; i++) {
    x = i;
    for (j = 0; j < yoko; j++) {
      if (bou[j][1] == x) {
        x = bou[j][2];
      } else if (bou[j][2] == x) {
        x = bou[j][1];
      }
    }
    kekka[x - 1] = i;
  }
  for (j = 0; j < tate; j++) {
    printf("%d\\n", kekka[j]);
  }
}
Problem p00011 (C++) — buggy submission, verdict: Runtime Error

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

void swap(int *, int *, int);
int main() {
  int w, n, i;
  cin >> w >> n;
  int *numline = new int[w];
  for (i = 0; i < w; ++i) {
    numline[i] = i + 1;
  }
  int *swapline = new int[2 * n];
  for (i = 0; i < 2 * n; i += 2) {
    char innum[10];
    cin >> innum;
    int m = 0;
    while (innum[m] != ',')
      ++m;
    if (m == 1) {
      swapline[i] = innum[0] - 48;
      if (strlen(innum) - m - 1 == 1)
        swapline[i + 1] = innum[2] - 48;
      else
        swapline[i + 1] = 10 * (innum[2] - 48) + (innum[3] - 48);
    } else {
      swapline[i] = 10 * (innum[0] - 48) + (innum[1] - 48);
      if (strlen(innum) - m - 1 == 1)
        swapline[i + 1] = innum[3] - 48;
      else
        swapline[i + 1] = 10 * (innum[3] - 48) + (innum[4] - 48);
    }
  }
  swap(numline, swapline, n);
  for (i = 0; i < w; ++i) {
    cout << numline[i] << endl;
  }
  delete[] numline;
  delete[] swapline;
  return 0;
}

void swap(int numline[], int swapline[], int n) {
  for (int i = 0; i < 2 * n; i += 2) {
    swap(numline[swapline[i] - 1], numline[swapline[i + 1] - 1]);
  }
}


Error: -6
malloc(): corrupted top size


Fixed submission:

#include <cstring>
#include <iostream>
#include <sstream>
#include <utility>
using namespace std;

void swap(int *, int *, int);
int main() {
  int w, n, i;
  cin >> w >> n;
  int *numline = new int;
  for (i = 0; i < w; ++i) {
    numline[i] = i + 1;
  }
  int *swapline = new int;
  for (i = 0; i < 2 * n; i += 2) {
    char innum[10];
    cin >> innum;
    int m = 0;
    while (innum[m] != ',')
      ++m;
    if (m == 1) {
      swapline[i] = innum[0] - 48;
      if (strlen(innum) - m - 1 == 1)
        swapline[i + 1] = innum[2] - 48;
      else
        swapline[i + 1] = 10 * (innum[2] - 48) + (innum[3] - 48);
    } else {
      swapline[i] = 10 * (innum[0] - 48) + (innum[1] - 48);
      if (strlen(innum) - m - 1 == 1)
        swapline[i + 1] = innum[3] - 48;
      else
        swapline[i + 1] = 10 * (innum[3] - 48) + (innum[4] - 48);
    }
  }
  swap(numline, swapline, n);
  for (i = 0; i < w; ++i) {
    cout << numline[i] << endl;
  }
  delete numline;
  delete swapline;
  return 0;
}

void swap(int numline[], int swapline[], int n) {
  for (int i = 0; i < 2 * n; i += 2) {
    swap(numline[swapline[i] - 1], numline[swapline[i + 1] - 1]);
  }
}
Problem p00011 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main(void) {
  int w, n, a[30][2], i, c, no, rs[30];

  scanf("%d%d", &w, &n);
  for (i = 0; n > i; i++) {
    scanf("%d", &a[i][0]);
    getchar();
    scanf("%d", &a[i][1]);
  }

  for (i = 1; w >= i; i++) {
    no = i;
    for (c = 0; n > c; c++) {
      if (a[c][0] == no)
        no = a[c][1];
      else if (a[c][1] == no)
        no = a[c][0];
    }
    rs[no - 1] = i;
  }
  for (i = 0; w > i; i++) {
    printf("%d\\n", rs[i]);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>

int main(void) {
  int w, n, a[30][2], i, c, no, rs[5];

  scanf("%d%d", &w, &n);
  for (i = 0; n > i; i++) {
    scanf("%d", &a[i][0]);
    getchar();
    scanf("%d", &a[i][1]);
  }

  for (i = 1; w >= i; i++) {
    no = i;
    for (c = 0; n > c; c++) {
      if (a[c][0] == no)
        no = a[c][1];
      else if (a[c][1] == no)
        no = a[c][0];
    }
    rs[no - 1] = i;
  }
  for (i = 0; w > i; i++) {
    printf("%d\\n", rs[i]);
  }

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

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

using namespace std;
void lots(int len, int a, int b, int array[]) {
  int buffer[len];
  for (int i = 0; i < len; i++) {
    if (i == a - 1) {
      buffer[i] = array[b - 1];
    } else if (i == b - 1) {
      buffer[i] = array[a - 1];
    } else {
      buffer[i] = array[i];
    }
  }
  for (int i = 0; i < len; i++) {
    array[i] = buffer[i];
  }
}

int main() {
  int len, duration, a, b;
  cin >> len;
  cin >> duration;
  int array[len];
  for (int i = 0; i < len; i++) {
    array[i] = i + 1;
  }
  for (int i = 0; i < duration; i++) {
    scanf("%d,%d", &a, &b);
    lots(len, a, b, array);
  }
  for (int i = 0; i < len; i++) {
    cout << array[i] << endl;
  }
}

Error: 0

Fixed submission:

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

using namespace std;
void lots(int len, int a, int b, int array[]) {
  int buffer[5];
  for (int i = 0; i < len; i++) {
    if (i == a - 1) {
      buffer[i] = array[b - 1];
    } else if (i == b - 1) {
      buffer[i] = array[a - 1];
    } else {
      buffer[i] = array[i];
    }
  }
  for (int i = 0; i < len; i++) {
    array[i] = buffer[i];
  }
}

int main() {
  int len, duration, a, b;
  cin >> len;
  cin >> duration;
  int array[len];
  for (int i = 0; i < len; i++) {
    array[i] = i + 1;
  }
  for (int i = 0; i < duration; i++) {
    scanf("%d,%d", &a, &b);
    lots(len, a, b, array);
  }
  for (int i = 0; i < len; i++) {
    cout << array[i] << endl;
  }
}
Problem p00011 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

int main() {
  int amida[33];
  for (int i = 0; i <= 31; ++i)
    amida[i] = i;
  int w, n;
  int a, b;
  std::scanf("%d %d", &w, &n);
  for (int i = 0; i < n; ++i) {
    std::scanf("%d,%d", &a, &b);
    amida[32] = amida[a];
    amida[a] = amida[b];
    amida[b] = amida[32];
  }
  for (int i = 1; i <= w; ++i)
    std::printf("%d\\n", amida[i]);
}


Error: 0

Fixed submission:

#include <iostream>
#include <string>

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

  int amida[33];
  for (int i = 0; i <= 31; ++i)
    amida[i] = i;
  int w, n;
  int a, b;
  std::string s;
  std::cin >> w;
  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    std::cin >> s;
    a = s.at(0) - '0';
    b = s.at(2) - '0';
    amida[32] = amida[a];
    amida[a] = amida[b];
    amida[b] = amida[32];
  }
  for (int i = 1; i <= w; ++i)
    std::cout << amida[i] << std::endl;
}
Problem p00011 (C++) — buggy submission, verdict: Runtime Error

#define _CRT_SECURE_NO_WARNINGS 1

#include <cstdio>

using namespace std;

int main() {
  int W, N, A[31], B[31], C[31];

  scanf("%d", &W);
  scanf("%d", &N);

  for (int i = 1; i <= N; i++) {
    scanf("%d,%d", &(A[i]), &(B[i]));
  }

  for (int i = 1; i <= W; i++) {
    int t = i;

    for (int j = 1; j <= N; j++) {
      if (A[j] == t) {
        t = B[j];
      } else if (B[j] == t) {
        t = A[j];
      }
    }

    C[t] = i;
  }

  for (int i = 1; i <= W; i++) {
    printf("%d\\n", C[i]);
  }

  return 0;
}

Error: -11

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS 1

#include <cstdio>

using namespace std;

int main() {
  int W, N, A[31], B[31], C[31];

  scanf("%d", W);
  scanf("%d", N);

  for (int i = 1; i <= N; i++) {
    scanf("%d,%d", &(A[i]), &(B[i]));
  }

  for (int i = 1; i <= W; i++) {
    int t = i;

    for (int j = 1; j <= N; j++) {
      if (A[j] == t) {
        t = B[j];
      } else if (B[j] == t) {
        t = A[j];
      }
    }

    C[t] = i;
  }

  for (int i = 1; i <= W; i++) {
    printf("%d\\n", C[i]);
  }

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

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

int main() {
  int line[40] = {};
  int linenum;
  int change;
  cin >> linenum >> change;
  for (int i = 1; i < linenum + 1; i++) {
    line[i] = i;
  }
  int sw, ap;
  char waste;
  for (int i = 0; i < change; i++) {
    cin >> sw >> waste >> ap;
    swap(line[sw], line[ap]);
  }
  for (int i = 1; i < linenum + 1; i++) {
    cout << line[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int line;
  int side;
  int sidenum1, sidenum2;
  int linenum[line];
  char waste;
  cin >> line >> side;
  for (int i = 0; i < line; i++) {
    linenum[i] = i + 1;
  }
  for (int i = 0; i < side; i++) {
    cin >> sidenum1 >> waste >> sidenum2;
    swap(linenum[sidenum1 - 1], linenum[sidenum2 - 1]);
  }
  for (int i = 0; i < line; i++) {
    cout << linenum[i] << endl;
  }
  return 0;
}
Problem p00011 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int w, n, a, b;
  char c;
  vector<int> ans;
  cin >> w >> n;

  for (int i = 0; i <= w; i++) {
    ans.push_back(i);
  }
  for (int i = 0; i < n; i++) {
    cin >> a >> c >> b;

    swap(ans[a], ans[b]);
  }

  for (int i = 1; i <= w; i++)
    cout << ans[i] << endl;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>

#define swap(a, b) a ^= b ^= a ^= b

using namespace std;

int main() {

  int w, n, a, b;
  cin >> w >> n;
  int *ans = new int(w + 1);

  for (int i = 0; i <= w; i++) {
    ans[i] = i;
  }

  for (int i = 0; i < n; i++) {
    scanf("%d,%d", &a, &b);
    swap(ans[a], ans[b]);
  }
  for (int i = 1; i <= w; i++) {
    cout << ans[i] << endl;
  }
  delete ans;
}