Matrix flipping--garlic (5)

Source: Internet
Author: User

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)

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.