Calculator Matrix Flip

Xiaomeng is currently working on an application that flips pictures. As you may know, pictures are actually made up of dots. So Xiaomeng wanted to make a program that could flip the matrix first to solve the core part of his problem.

input format

The first line of input consists of integers M,N,T(0<N,M<200)M,N,T(0<N,M<200) separated by spacesM,N,T(0<N,M<200)TTThe value of T is000 or111 . whereMMM andNNN represents the number of rows and columns of the matrix to be processed, respectively,TTT is00When 0 means flip left and right, it is111 means upside down.

MM afterM lines, each line includes NNseparated by spacesN integers, sequentially the data for each row of the input matrix.

output format

Output includes MMM rowsNNN columns, each number is separated by a space, and there is a spaceat the end of each row, which represents the matrix after being flipped as required.

sample input

4 4 1
1 2 3 4
5 6 7 8
9 0 1 2
3 4 5 6

Sample output

3 4 5 6
9 0 1 2
5 6 7 8
1 2 3 4


#include<iostream>

using namespace std;

intmain()
{
    int M,N,T,i,j,x;
    cin>>M>>N>>T;
    int a[200][200];
    for (i=0;i<M;i++){
        for (j=0;j<N;j++)
            cin>>a[i][j];
    }
    
    if (T==0){
        for (i=0;i<M;i++){
           for (j=N-1;j>=0;j--) {
               cout<<a[i][j]<<" ";
               if(j%N==0)
                   cout<<endl;
           }
        }

    }
    
    if (T==1){
       for(i=M-1;i>=0;i--){
           for (j=0;j<N;j++){
               cout<<a[i][j]<<" ";
               if((j+1)%N==0)
                   cout<<endl;}
       }
    }
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324782935&siteId=291194637