Question:
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, indicating 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
My answer: Access
Time Complexity: M * n
// Juzheng. cpp: defines the entry point for the console application.
# Include "iostream"
# Include "vector"
Using namespace STD;
Int main ()
{
Int I, j, M, N, T;
Int A [200] [200];
Cin> m> N> T;
For (I = 0; I <m; I ++ ){
For (j = 0; j <n; j ++ ){
Cin> A [I] [J];
}
}
If (t = 0)
{
For (j = 0; j <m; j ++)
For (I = 1; I <= N; I ++)
{
Cout <A [J] [n-I] <"";
If (I) % N = 0)
Cout <Endl;
}
}
Else if (t = 1)
{
For (j = 1; j <= m; j ++)
For (I = 0; I <n; I ++)
{
Cout <A [M-J] [I] <"";
If (I + 1) % N = 0)
Cout <Endl;
}
}
Return 0;
}
ACM programming question matrix flip