Problem p00819 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

string c_j(string str);
string c_c(string str);
string c_e(string str);
string c_a(string str);
string c_p(string str);
string c_m(string str);

int main() {
  int n;
  string order, message;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> order >> message;
    string ans = message;
    for (int j = order.length() - 1; j >= 0; j--) {
      if (order[j] == 'J')
        ans = c_j(ans);
      else if (order[j] == 'C')
        ans = c_c(ans);
      else if (order[j] == 'E')
        ans = c_e(ans);
      else if (order[j] == 'A')
        ans = c_a(ans);
      else if (order[j] == 'P')
        ans = c_p(ans);
      else if (order[j] == 'M')
        ans = c_m(ans);
    }
    cout << ans << endl;
  }
  return 0;
}

string c_j(string str) {
  char c;
  c = str[str.length() - 1];
  str.erase(str.end() - 1);
  str = c + str;
  return str;
}

string c_c(string str) {
  char c;
  c = str[0];
  str.erase(str.begin());
  str += c;
  return str;
}

string c_e(string str) {
  string a;
  int l = str.length();
  a = str.substr(0, l / 2);
  if (l % 2 == 1) {
    char c = str[l / 2];
    str.erase(str.begin(), str.begin() + (l / 2) + 1);
    str += c;
    str += a;
  } else {
    str.erase(str.begin(), str.begin() + (l / 2));
    str += a;
  }
  return str;
}

string c_a(string str) {
  reverse(str.begin(), str.end());
  return str;
}

string c_p(string str) {
  for (int i = 0; i < str.length(); i++) {
    if (isdigit(str[i])) {
      int n = str[i] - '0';
      n--;
      if (n == -1)
        n = 9;
      str[i] = n + '0';
    }
  }
  return str;
}

string c_m(string str) {
  for (int i = 0; i < str.length(); i++) {
    if (isdigit(str[i])) {
      int n = str[i] - '0';
      n = (n + 1) % 10;
      str[i] = n + '0';
    }
  }
  return str;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

void c_j(string str);
void c_c(string str);
void c_e(string str);
void c_a(string str);
void c_p(string str);
void c_m(string str);

int main() {
  int n;
  string order, message;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> order >> message;
    for (int j = order.length() - 1; j >= 0; j++) {
      if (order[j] == 'J')
        c_j(message);
      else if (order[j] == 'C')
        c_c(message);
      else if (order[j] == 'E')
        c_e(message);
      else if (order[j] == 'A')
        c_a(message);
      else if (order[j] == 'P')
        c_p(message);
      else if (order[j] == 'M')
        c_m(message);
    }
    cout << message << endl;
  }
  return 0;
}

void c_j(string str) {
  char c;
  c = str[str.length() - 1];
  str.erase(str.end());
  str = c + str;
}

void c_c(string str) {
  char c;
  c = str[0];
  str.erase(str.begin());
  str += c;
}

void c_e(string str) {
  string a;
  int l = str.length();
  a = str.substr(0, l / 2);
  if (l % 2 == 1) {
    char c = str[l / 2 + 1];
    str.erase(str.begin(), str.begin() + l);
    str += c;
    str += a;
  } else {
    str.erase(str.begin(), str.begin() + (l - 1));
    str += a;
  }
}

void c_a(string str) { reverse(str.begin(), str.end()); }

void c_p(string str) {
  for (int i = 0; i < str.length() - 1; i++) {
    if (isdigit(str[i])) {
      int n = str[i] - '0';
      n--;
      if (n == -1)
        n = 9;
      str[i] = n + '0';
    }
  }
}

void c_m(string str) {
  for (int i = 0; i < str.length() - 1; i++) {
    if (isdigit(str[i])) {
      int n = str[i] - '0';
      n = (n + 1) % 10;
      str[i] = n + '0';
    }
  }
}