#include <iostream>
#include <iomanip>
#include <algorithm>
const unsigned lineWidth = 80 ;
const unsigned columnWidth = 10 ;
const unsigned columns = lineWidth / columnWidth ;
void print( const int* t, unsigned size )
{
for ( unsigned i=0; i<size; ++i )
{
std::cout << std::setw(columnWidth) << t[i] ;
if ( i > columns )
std::cout << '\n' ;
}
std::cout << '\n' ;
}
void print( const int* t, const unsigned* indices, unsigned size )
{
for ( unsigned i=0; i<size; ++i )
{
std::cout << std::setw(columnWidth) << t[indices[i]] ;
if ( i > columns )
std::cout << '\n' ;
}
std::cout << '\n' ;
}
int main()
{
const unsigned sz = 10 ;
int arr[sz] = {1, 5, 22, 14, 6, -5, 7, 9, 12, 15 } ;
unsigned arr_index[sz] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } ;
print(arr, sz) ;
print(arr, arr_index, sz) ;
std::cout << '\n' ;
std::sort(std::begin(arr_index), std::end(arr_index), [&](unsigned i, unsigned j){ return arr[i] < arr[j]; }) ;
print(arr, sz) ;
print(arr, arr_index, sz) ;
std::cout << '\n' ;
std::sort(std::begin(arr_index), std::end(arr_index), [&](unsigned i, unsigned j){ return arr[j] < arr[i]; }) ;
print(arr,sz) ;
print(arr, arr_index, sz) ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8aW9tYW5pcD4KI2luY2x1ZGUgPGFsZ29yaXRobT4KIAogY29uc3QgdW5zaWduZWQgbGluZVdpZHRoID0gODAgOwogY29uc3QgdW5zaWduZWQgY29sdW1uV2lkdGggPSAxMCA7CiBjb25zdCB1bnNpZ25lZCBjb2x1bW5zID0gbGluZVdpZHRoIC8gY29sdW1uV2lkdGggOwogCnZvaWQgcHJpbnQoIGNvbnN0IGludCogdCwgdW5zaWduZWQgc2l6ZSApCnsgCiAgICBmb3IgKCB1bnNpZ25lZCBpPTA7IGk8c2l6ZTsgKytpICkKICAgIHsKICAgICAgICBzdGQ6OmNvdXQgPDwgc3RkOjpzZXR3KGNvbHVtbldpZHRoKSA8P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