首页 > 解决方案 > 使用 Zybooks 编译器获取返回码 -9 (SIGKILL),但代码在不同的编译器上运行良好

问题描述

现在在大学学习 C++,对于一个项目,我必须编写一个程序,列出所有不同名称的排列。该代码在 repl.it 上运行良好,但在 Zybooks(用于上课的网站)上出现错误。我该怎么办?

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

using namespace std;

void AllPermutations(vector<string> &permList, vector<string> &nameList) {
   string tmpName;
   int i;
   
   if (permList.size() == 3){
      for (i = 0; i < permList.size(); ++i){
         cout << permList.at(i) << " ";}
         cout << endl;
}
   else {
      for (i = 0; i < nameList.size(); ++i){
         tmpName = nameList.at(i);
         nameList.erase(nameList.begin() + i);
         permList.push_back(tmpName);
         
         AllPermutations(permList, nameList);
         
         nameList.insert(nameList.begin() + i, tmpName);
         permList.pop_back();
         }
   }
}
int main() {
   vector<string> nameList(0);
   vector<string> permList(0);
   string name;
   
   getline(cin,name);
   
   while (name != "-1"){
      nameList.push_back(name);
      getline(cin,name);
      }
   
   AllPermutations(permList, nameList);
   return 0;
}

标签: c++debugging

解决方案


推荐阅读