Xiao Meng recently in the application of a rollover picture, you may also know that the picture is actually made up of a point. So, Xiao Meng want to first do a can flip the matrix program, to solve the core of his problem.
The input first line includes integers separated by spaces M, N, T (0 < M < 200,0 < N < 200,t=0 or 1), where M and n represent the number of rows and columns of the matrix to be processed, and T is 0 for left and right flips, and 1 for up and down.
After the M line, each row consists of n integers separated by a space, followed by the data for each row of the input matrix.
The output consists of M row n columns, separated by a space between each number, with a space at the end of each line, representing the matrix after the request is flipped.
Example 1
Input:
3 4 5 69 0 1 25 6 7 81 2 3 4
Output:
4 4 11 2 3 45 6 7 89 0 1 23 4 5 6
Code implementation:
#include <stdio.h>intMain () {intmat[ $][ $]; intM, N, T; scanf (" %d%d%d", &m, &n, &T); intR, C; for(R =0; R < M; r++ ) { for(c =0; c < N; C++) {scanf ("%d", &Mat[r][c]); } } // Change inttemp =0; if(T = =1) { for(c =0; c < N; C++ ) { for(R =0; R <= (M-1) /2; r++) { // up Downtemp =Mat[r][c]; MAT[R][C]= Mat[m-1-R] [C]; Mat[m-1-R][C] =temp; } } } Else if(T = =0) { for(R =0; R < M; r++ ) { for(c =0; C <= (N-1) /2; C++) { // Left Righttemp =Mat[r][c]; MAT[R][C]= Mat[r][n-1-c]; Mat[r][n-1-C] =temp; } } } //Output for(R =0; R < M; r++ ) { for(c =0; c < N; C++) {printf ("%d", Mat[r][c]); } printf ("\ n"); } return 0;}
Matrix flipping--garlic (5)