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

#include <iostream>
#include <map>
#include <stdlib.h>
#include <string>

int OFA(); // Operation of Frequency of Appearance

void listen_nums(int nums[], const int count_nums);
void calc_appearance(int nums[], int appearance[], const int count_nums);
void write_calcedArray(int nums[], int appearance[], const int count_nums);
bool is_notMoved(int nums[], int appearance[], const int count_nums);
void echo_intArray(int array[], const int length);

//-------------------------main-------------------------------
int main() {
  while (OFA())
    ;
  return 0;
}

int OFA() {
  using namespace std;
  int count_nums;
  cin >> count_nums;
  if (!count_nums) {
    return 0;
  }
  int nums[count_nums];
  listen_nums(nums, count_nums);
  int appearance[count_nums];

  int calcCount = 0;
  for (; 1;) {
    calc_appearance(nums, appearance, count_nums);
    if (is_notMoved(nums, appearance, count_nums)) {
      cout << calcCount << endl;
      echo_intArray(appearance, count_nums);
      return 1;
    } else {
      calcCount++;
      write_calcedArray(
          nums, appearance,
          count_nums); // numsの先頭ポインタを操作後文字列に置き換え
    }
  }
}
//-----------------------------------------------------------

void listen_nums(int nums[], const int count_nums) {
  using namespace std;
  int i = 0;
  string str;
  while (i < count_nums - 1) {
    getline(cin, str, ' ');
    nums[i] = atoi(str.c_str());
    i++;
  }
  cin >> nums[i];
}

void calc_appearance(int nums[], int appearance[], const int count_nums) {
  using namespace std;

  map<int, int> count_eachNums;

  int i;
  for (i = 0; i < count_nums; i++) {
    if (count_eachNums.find(nums[i]) == count_eachNums.end()) {
      count_eachNums.insert(map<int, int>::value_type(nums[i], 1));
    } else {
      count_eachNums[nums[i]]++;
    }
  }
  for (i = 0; i < count_nums; i++) {
    appearance[i] = count_eachNums[nums[i]];
  }
}

void write_calcedArray(int nums[], int appearance[], const int count_nums) {
  for (int i = 0; i < count_nums; i++) {
    nums[i] = appearance[i];
  }
}

bool is_notMoved(int nums[], int appearance[], const int count_nums) {
  for (int i = 0; i < count_nums; i++) {
    if (nums[i] != appearance[i]) {
      return false;
    }
  }
  return true;
}
void echo_intArray(int array[], const int length) {
  using namespace std;

  cout << array[0];
  for (int i = 1; i < length; i++) {
    cout << " " << array[i];
  }
  cout << endl;
}

Error: -11

Fixed submission:

#include <iostream>
#include <map>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int OFA(); // Operation of Frequency of Appearance

void listen_nums(int nums[], const int count_nums);
void calc_appearance(int nums[], int appearance[], const int count_nums);
void write_calcedArray(int nums[], int appearance[], const int count_nums);
bool is_notMoved(int nums[], int appearance[], const int count_nums);
void echo_intArray(int array[], const int length);

//-------------------------main-------------------------------
int main() {
  while (OFA())
    ;
  return 0;
}

int OFA() {
  using namespace std;
  int count_nums;
  cin >> count_nums;
  if (!count_nums) {
    return 0;
  }
  int nums[count_nums];
  listen_nums(nums, count_nums);
  int appearance[count_nums];

  int calcCount = 0;
  for (; 1;) {
    calc_appearance(nums, appearance, count_nums);
    if (is_notMoved(nums, appearance, count_nums)) {
      cout << calcCount << endl;
      echo_intArray(appearance, count_nums);
      return 1;
    } else {
      calcCount++;
      write_calcedArray(
          nums, appearance,
          count_nums); // numsの先頭ポインタを操作後文字列に置き換え
    }
  }
}
//-----------------------------------------------------------

void listen_nums(int nums[], const int count_nums) {
  char stringBuff[1024];

  for (; 1;) {
    fgets(stringBuff, sizeof(stringBuff), stdin);
    if (strcmp(stringBuff, "\\r\\n") != 0) {
      break;
    }
  }
  nums[0] = atoi(strtok(stringBuff, " "));
  for (int i = 1; i < count_nums - 1; i++) {
    nums[i] = atoi(strtok(NULL, " "));
  }
  nums[count_nums - 1] = atoi(strtok(NULL, "\\r\\n"));
}

void calc_appearance(int nums[], int appearance[], const int count_nums) {
  using namespace std;

  map<int, int> count_eachNums;

  int i;
  for (i = 0; i < count_nums; i++) {
    if (count_eachNums.find(nums[i]) == count_eachNums.end()) {
      count_eachNums.insert(map<int, int>::value_type(nums[i], 1));
    } else {
      count_eachNums[nums[i]]++;
    }
  }
  for (i = 0; i < count_nums; i++) {
    appearance[i] = count_eachNums[nums[i]];
  }
}

void write_calcedArray(int nums[], int appearance[], const int count_nums) {
  for (int i = 0; i < count_nums; i++) {
    nums[i] = appearance[i];
  }
}

bool is_notMoved(int nums[], int appearance[], const int count_nums) {
  for (int i = 0; i < count_nums; i++) {
    if (nums[i] != appearance[i]) {
      return false;
    }
  }
  return true;
}
void echo_intArray(int array[], const int length) {
  using namespace std;

  cout << array[0];
  for (int i = 1; i < length; i++) {
    cout << " " << array[i];
  }
  cout << endl;
}