c++ - 使用 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# - 为什么这个代码在我打开它后会改变我的主窗体背景颜色?
- java - 为什么迭代器中的修改在迭代期间不可见?
- reactjs - React native 获取和使用 usestate 来获取依赖的数据项
- c++ - 何时从函数返回?
- r - 使用 nlsLM 在函数内使用 combn 进行非线性回归
- c# - 在 C# 中将 png 数据保存到文件中
- c - 为什么 termcaps 在 `write` 系统调用之前不起作用?
- python - 多处理 fork() 与 spawn()
- html - 删除网页上的空格(边距)
- javascript - 删除 mouseleave (Jquery) 中的附加元素