Workshop problem
code seems to work randomly at times and fail at random too with same input file.unknown
c_cpp
4 years ago
1.6 kB
13
Indexable
#include<iostream>
using namespace std;
//Define the structs Workshops and Available_Workshops.
//Implement the functions initialize and CalculateMaxWorkshops
struct Workshop{
int start_time;
int duration;
int end_time;
};
struct Available_Workshops{
int n;
Workshop *workshops = new Workshop[n];
};
Available_Workshops* initialize (int start_time[],int duration[],int n){
cout<<"testing ok."<<endl;
Available_Workshops *data = new Available_Workshops[n];
//cout<<"testing ok.";
for(int i=0;i<n;i++){
cout<<"i: "<<i<<endl;
data[i].workshops->start_time = start_time[i];
data[i].workshops->duration = duration[i];
data[i].workshops->end_time = start_time[i]+duration[i];
}
cout<<"testing ok.end of for loop inside initialize."<<endl;
return data;
}
int CalculateMaxWorkshops(Available_Workshops* ptr){
int count=1;
return count;
}
int main(int argc, char *argv[]) {
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
//cout<<"testing ok. starting point.";
int n; // number of workshops
cin >> n;
// create arrays of unknown size n
int* start_time = new int[n];
int* duration = new int[n];
for(int i=0; i < n; i++){
cin >> start_time[i];
}
for(int i = 0; i < n; i++){
cin >> duration[i];
}
Available_Workshops * ptr;
ptr = initialize(start_time,duration, n);
cout << CalculateMaxWorkshops(ptr) << endl;
return 0;
}Editor is loading...