Control C401C P27526


Statement
 

pdf   zip

thehtml

Your task is to write a program that starts reading and printing a matrix of integers n × m. Afterwards, for each pair of natural numbers j and k given, print the previous matrix with the columns j and k swapped. The columns are counted from 0 to m − 1.

Using the definition

typedef vector<vector<int> > Matrix;

your program must implement and use the function

void swap(Matrix& mat, int j, int k);

that, given a matrix |mat| and the natural numbers j and k, swaps the columns j and k of |mat|. The indices j and k will always be between 0 and the number of columns of |mat| minus one.

Input

The input starts with the size n > 0 and m > 0 of the matrix, followed by n lines with m elements each one, followed by a sequence of pairs j, k. Each j and each k is between 0 and m − 1.

Output

Your program must print the sequence of matrices composed of the read matrix, followed by the resulted matrix of each swap. Notice that print lines with five dashes to separate the matrices, at the beginning and in the end.

Public test cases
  • Input

    4  6
    11 22 33 46 15 32
    41 33 94 58 71 32
    56 23 45 98 21 12
    54 15 37 26 17 99
    
    2 3
    5 4
    0 1
    5 4
    

    Output

    -----
    11 22 33 46 15 32
    41 33 94 58 71 32
    56 23 45 98 21 12
    54 15 37 26 17 99
    -----
    11 22 46 33 15 32
    41 33 58 94 71 32
    56 23 98 45 21 12
    54 15 26 37 17 99
    -----
    11 22 46 33 32 15
    41 33 58 94 32 71
    56 23 98 45 12 21
    54 15 26 37 99 17
    -----
    22 11 46 33 32 15
    33 41 58 94 32 71
    23 56 98 45 12 21
    15 54 26 37 99 17
    -----
    22 11 46 33 15 32
    33 41 58 94 71 32
    23 56 98 45 21 12
    15 54 26 37 17 99
    -----
    
  • Input

    3 4
    1 0 1 1
    0 2 0 3
    1 1 9 5
    

    Output

    -----
    1 0 1 1
    0 2 0 3
    1 1 9 5
    -----
    
  • Input

    2 2
    6 7
    8 9
    
    0 1
    1 0
    0 0
    1 1
    

    Output

    -----
    6 7
    8 9
    -----
    7 6
    9 8
    -----
    6 7
    8 9
    -----
    6 7
    8 9
    -----
    6 7
    8 9
    -----
    
  • Input

    2 1
    7
    9
    
    0 0
    0 0
    

    Output

    -----
    7
    9
    -----
    7
    9
    -----
    7
    9
    -----
    
  • Information
    Author
    Professorat de P1
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++