写一道题写到一半的时候出现的问题,放在本地运行就是几秒后闪退,放在洛谷在线ide运行这个代码提示超出内存限制,然后我找到了一个for循环的代码块,在代码的57行到66行的两个for循环,只要我把这两个代码块注释掉本地就能正常运行,但在在线ide上运行就提示运行时错误,我把for循环单独拉出来运行都没事,但是放入代码块就出问题了,求解惑,具体问题代码块如下,检查了n遍完全没看到有什么问题,放入总的代码块就出问题了。
for(int i = 1;i<=n;i++){
for (int x = 1;x<=m;x++){
//cin >> workpieces[i].process[x][0];
}
}
for(int i = 1;i<=n;i++){
for (int x = 1;x<=m;x++){
cin >> workpieces[i].process[x][1];
}
}
下面是总的代码
#include <iostream>
#include <cstring>
using namespace std;
struct Machine{
int task[10000];
int length = 0;
void add(int workpiece,int time,int point = -1){
if (point != -1){
length=point;
}
for (int i = length;i<length+time;i++){
task[i] = workpiece;
}
length+=time;
}
void printTask(){
for(int i = 0;i<length;i++){
cout << task[i]<<' ';
}
cout <<endl;
}
};
struct Workpiece{
int number;
// 工序机器 工序时间
//[[ 1, 3 ]]
// 工序
int process[30][5];
int length = 1;
/*
void add(int machine,int time){
process[length][0] = machine;
process[length++][1] = time;
}*/
void printProcess(){
for (int i = 1;i<length-1;i++){
cout << process[i][0]<<" "<<process[i][1]<<endl;
}
}
};
int main(){
int m,n;//m为机器数 n为工件数
int order[400];
Machine machines[20];
Workpiece workpieces[n+10];
//m = 2,n=3;
cin >> m >> n;
//输入安排顺序
for (int i = 0;i<m*n;i++){
cin >>order[i];
}
//输入工件工序机器号
for(int i = 1;i<=n;i++){
for (int x = 1;x<=m;x++){
//cin >> workpieces[i].process[x][0];
}
}
for(int i = 1;i<=n;i++){
for (int x = 1;x<=m;x++){
cin >> workpieces[i].process[x][1];
}
}
//workpieces[1].printProcess();
//输入工件工序时间
}