Problem p02261 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

struct Card {
  char suit;
  int value;
};

void print(std::vector<Card> cards);

vector<Card> bubble(std::vector<Card> C, int N) {
  rep(i, N) {
    int j = N - 1;
    while (j > i) {
      if (C[j].value < C[j - 1].value) {
        swap(C[j], C[j - 1]);
      }
      j--;
    }
  }
  return C;
}

vector<Card> selection(std::vector<Card> C, int N) {
  rep(i, N) {
    int minj = i;
    int j = i;
    while (j < N) {
      if (C[j].value < C[minj].value) {
        minj = j;
      }
      j++;
    }
    if (i != minj) {
      swap(C[i], C[minj]);
    }
  }
  return C;
}

void print(std::vector<Card> cards, int N) {
  Card card_last = cards[N - 1];
  rep(i, N - 1) {
    if (cards[i].value == 0) {
      break;
    }
    std::cout << cards[i].suit << cards[i].value << " ";
  }
  std::cout << card_last.suit << card_last.value << '\n';
}

void check(vector<Card> C1, vector<Card> C2, int N) {
  rep(i, N) {
    if (!(C1[i].suit == C2[i].suit)) {
      std::cout << "Not stable" << '\n';
      return;
    }
  }
  std::cout << "Stable" << '\n';
}

int main() {
  std::vector<Card> C1(32);
  std::vector<Card> C2(32);

  int N;
  cin >> N;
  rep(i, N) { cin >> C1[i].suit >> C1[i].value; }

  rep(i, N) { C2[i] = C1[i]; }

  // print(C1);

  C1 = bubble(C1, N);

  C2 = selection(C2, N);

  print(C1, N);
  std::cout << "Stable" << '\n';
  print(C2, N);
  check(C1, C2, N);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

struct Card {
  char suit;
  int value;
};

void print(std::vector<Card> cards);

vector<Card> bubble(std::vector<Card> C, int N) {
  rep(i, N) {
    int j = N - 1;
    while (j > i) {
      if (C[j].value < C[j - 1].value) {
        swap(C[j], C[j - 1]);
      }
      j--;
    }
  }
  return C;
}

vector<Card> selection(std::vector<Card> C, int N) {
  rep(i, N) {
    int minj = i;
    int j = i;
    while (j < N) {
      if (C[j].value < C[minj].value) {
        minj = j;
      }
      j++;
    }
    if (i != minj) {
      swap(C[i], C[minj]);
    }
  }
  return C;
}

void print(std::vector<Card> cards, int N) {
  Card card_last = cards[N - 1];
  rep(i, N - 1) {
    if (cards[i].value == 0) {
      break;
    }
    std::cout << cards[i].suit << cards[i].value << " ";
  }
  std::cout << card_last.suit << card_last.value << '\n';
}

void check(vector<Card> C1, vector<Card> C2, int N) {
  rep(i, N) {
    if (!(C1[i].suit == C2[i].suit)) {
      std::cout << "Not stable" << '\n';
      return;
    }
  }
  std::cout << "Stable" << '\n';
}

int main() {
  std::vector<Card> C1(36);
  std::vector<Card> C2(36);

  int N;
  cin >> N;
  rep(i, N) { cin >> C1[i].suit >> C1[i].value; }

  rep(i, N) { C2[i] = C1[i]; }

  // print(C1);

  C1 = bubble(C1, N);

  C2 = selection(C2, N);

  print(C1, N);
  std::cout << "Stable" << '\n';
  print(C2, N);
  check(C1, C2, N);

  return 0;
}