#include <iostream>
using namespace std;
void swap_func(int *a,int *b){
int swap;
swap = *a;
*a=*b;
*b=swap;
}
int main() {
cout<<"The gantt chart\n";
int n,*pid_arr,*bt,*ar_arr,tmp;
cin>>n;
bt = new int[n];
ar_arr = new int[n];
pid_arr = new int[n];
for (int i =0;i<n;i++){
cin>>pid_arr[i];
}
for (int i =0;i<n;i++){
cin>>bt[i];
}
for (int i =0;i<n;i++){
cin>>ar_arr[i];
}
for (int i =0;i<n;i++){
for(int j=i;j<n;j++){
if(bt[i]>=bt[j]){
swap_func(&ar_arr[i],&ar_arr[j]);
swap_func(&bt[i],&bt[j]);
swap_func(&pid_arr[i],&pid_arr[j]);
}
}
}
for(int i=0;i<n;i++){
printf("P%d ",pid_arr[i]);
}
cout<<endl;
for(int i=0;i<n;i++){
tmp = 0;
for(int j=0;j<i;j++){
tmp+=bt[j];
}
cout<<tmp<<" ";
}
cout<<tmp+bt[n-1];
return 0;
}
using namespace std;
void swap_func(int *a,int *b){
int swap;
swap = *a;
*a=*b;
*b=swap;
}
int main() {
cout<<"The gantt chart\n";
int n,*pid_arr,*bt,*ar_arr,tmp;
cin>>n;
bt = new int[n];
ar_arr = new int[n];
pid_arr = new int[n];
for (int i =0;i<n;i++){
cin>>pid_arr[i];
}
for (int i =0;i<n;i++){
cin>>bt[i];
}
for (int i =0;i<n;i++){
cin>>ar_arr[i];
}
for (int i =0;i<n;i++){
for(int j=i;j<n;j++){
if(bt[i]>=bt[j]){
swap_func(&ar_arr[i],&ar_arr[j]);
swap_func(&bt[i],&bt[j]);
swap_func(&pid_arr[i],&pid_arr[j]);
}
}
}
for(int i=0;i<n;i++){
printf("P%d ",pid_arr[i]);
}
cout<<endl;
for(int i=0;i<n;i++){
tmp = 0;
for(int j=0;j<i;j++){
tmp+=bt[j];
}
cout<<tmp<<" ";
}
cout<<tmp+bt[n-1];
return 0;
}
Comments
Post a Comment