Question 5th: matrix flip

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.