Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created December 10, 2013 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7897937 to your computer and use it in GitHub Desktop.
Save anonymous/7897937 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
using namespace std;
//Function: Print_Array
void Print_Array(const vector<int>& Arr, int size){
cout << "Contents of the array" << endl;
for(int i = 0; i < size; i++){
cout << Arr[i] << " ";
}
cout << endl;
}
//Function: swap
void swap(int& a, int & b){
int temp=a;
a=b;
b=temp;
}
//Function: vector_sort
void vector_sort(vector<int>& Arr){
int max_size=-1;
for(int j=0; j<Arr.size(); j++){
for(int i=0; i<Arr.size()-1; i++){
if(Arr[i]<Arr[i+1]){
swap(Arr[i],Arr[i+1]);
}
}
}
}
int main(){
//First, we should declare the vectors to get them out of the way.
vector<int> start_time;
vector<int> end_time;
vector<int> schedule;
vector<int> activities;
int num_act;
cout << "How many activities are there scheduled for today?";
cin >> num_act;
int start;
int end;
//to keep the while loop set, we need to keep count of how many enteries there are, or it will be infinite.
int act_entered=0;
while(act_entered<num_act){
cout << "Enter the start time:";
cin >> start;
start_time.push_back(start);
cout << "Enter the end time:";
cin >> end;
end_time.push_back(end);
act_entered++;
}
//Now that the vectors are entered, we should compute how long each activity is.
int act_time;
int num_acts=0;
int total=0;
int long_time=-1;
for(int i=0; i<num_act; i++){
act_time= end_time[i]-start_time[i];
if(long_time<act_time){
long_time=act_time;
}
num_acts=i+1;
activities.push_back(act_time);
cout << "The time for activity " << num_acts << " is: " << act_time << endl;
total=total+act_time;
}
int cur_time=0;
int day_time=24;
for(int k=0; k<num_act; k++){
while(end_time[k]>=cur_time){
cur_time=end_time[k];
}
schedule.push_back(cur_time);
}
int num;
num=schedule.size();
Print_Array(schedule, num);
cout << endl;
Print_Array(start_time, num_act);
cout << endl;
cout << "Cur_time: " << cur_time << endl;
cout << endl;
cout << "Long_time: " << long_time << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment