我尝试将随机函数用于不同的事情。现在它可以工作,但我遇到一个问题是我想在我的代码中随机生成 F 但它们之后需要变成数组。我也需要使用它,如果我需要一个一个地做,我认为我的代码会太长而且太乱。你知道我该怎么做吗?
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(){
srand(time(0));
//random numbers 1 to 10 for Time:
int t = rand() % 10 + 1 ;
cout << "There is "<< t << " Time;
int* F1 = new int [t];
int* F2 = new int [t];
int* F3 = new int [t];
int* F4 = new int [t];
int* F5 = new int [t];
cout << "Time per F: 0 Not available, 1 available;
//For F1
for(int i = 0; i < t; i++){
//random numbers 0 or 1:
F1[i] = rand() % 2 ;
}
cout << "The Time for F1 is ";
for(int a = 0; a < t; a++){
cout << " "<< F1[a] <<" ";
}
//For F2
for(int j = 0; j < t; j++){
//random numbers 0 or 1:
F2[j] = rand() % 2 ;
}
cout << "The Time slot for F2 is ";
for(int b = 0; b < t; b++){
cout << " "<< F2[b] << " ";
}
return 0;
}
谢谢
编辑:你给我的解决方案有助于找到我做的解决方案 int F[em][t];