Question 5th: matrix flip
Question 5th: matrix flip
Xiao Meng has recently made an application to flip images. You may also know that images are actually composed of vertices. Therefore, Xiao Meng wants to first create a program that can flip the Matrix to solve the core part of his problem.
The first line of the input includes integers M, N, and T separated by spaces (0 <M <200, 0 <N <, T = 0 or 1 ), M and N represent the number of rows and columns of the matrix to be processed, respectively. If T is 0, it indicates turning left and right, and 1 indicates turning up and down.
Next M rows, each line contains N integers separated by spaces, which are the data of each row of the input matrix in turn.
The output includes M rows and N columns. Each number is separated by a space. Each row has a space at the end of the line, indicating the matrix after turning as required.
Sample Input
4 4 11 2 3 45 6 7 89 0 1 23 4 5 6
Sample output
3 4 5 6 9 0 1 2 5 6 7 8 1 2 3 4
Answer:
#include
int main(){int m,n,t,num[200][200],i,j;scanf("%d%d%d",&m,&n,&t);for(j = 0;j < m;j++){for(i = 0;i < n;i++)scanf("%d",&num[j][i]);}if(t == 1){for(j = m-1;j >= 0;j--){for(i = 0;i < n;i++){printf("%d",num[j][i]);if(i != n-1)printf(" ");}if(j != 0)printf("\n");}}else{for(j = 0;j < m;j++){for(i = n-1;i >= 0;i--){printf("%d",num[j][i]);if(i != 0)printf(" ");}if(j != m-1)printf("\n");}} }
If you cannot understand it, please leave a message or leave an email !!! O (partition _ partition) o