#include <iostream>
#include <iomanip>
const int maxx = 1000;
int Gasoline[maxx];
int Distance[maxx];
int subG[maxx], indexG[maxx];
int subD[maxx], indexD[maxx];
int N; /*the number of touring-group*/
int M; /*the number of bus */
void swap ( int *r, int *c )
{
int temp = *r;
*r = *c;
*c = temp;
}
bool ascending ( int a, int b ) { return b < a; }
bool descending ( int a, int b ) { return b > a; }
void bubble ( int array[], int size, bool (*compare)(int, int ) )
{
for ( int i = 2; i <= size; i++ )
for ( int j = 1; j <= size-1; j++ )
if ( (*compare) (array[j], array[j+1]) )
{
swap ( &array[j], &array[j+1] );
}
}
void InputData()
{
cout << "Enter the number of group : " ; cout << "Enter the number of bus : ";
cout << "----------------" << endl
;
for ( int i = 1; i <= M; i++ )
{
cout << "The bus : "<< i
<< " cost : "; subG[i] = Gasoline[i];
}
for ( int i = 1; i <= N; i++ )
{
cout << "The group : "<< i
<< " distance : "; subD[i] = Distance[i];
}
/*luu giu index*/
for ( int i = 1; i <= M; i++ )
{
indexD[i] = i;
indexG[i] = i;
}
}
/*Sort data follow order the car cost more gas serve the longer distance*/
void SortData()
{
cout << endl
<< "-------------------------" << endl
; bubble ( subG, M, ascending );
bubble ( subD, N, descending);
}
void Process()
{
int sum = 0;
for ( int i = 1; i <= N; i++ )
{
sum = sum + subD[i]*subG[i];
}
cout << "The total gasoline consumed : " << sum
;
/*Search for former index*/
int index_Gas = 1;
for ( int i = 1; i <= M; i++ )
{
for ( int j = 1; j <= M; j++ )
{
if ( subG[i] == Gasoline[j] )
{
indexG[index_Gas] = j;
index_Gas++;
}
}
}
int index_Dis = 1;
for ( int i = 1; i <= N; i++ )
{
for ( int j = 1; j <= N; j++ )
{
if ( subD[i] == Distance[j] )
{
indexD[index_Dis] = j;
index_Dis++;
}
}
}
/******************************************/
}
void OutPut()
{
for ( int i = 1; i <= N; i++ )
{
cout << "The bus [" << indexG
[i
] << "]"; cout << " serves the group [" << indexD
[i
] << "]"; }
}
void main()
{
InputData();
SortData();
Process();
OutPut();
}