zoukankan      html  css  js  c++  java
  • 计蒜客--矩阵翻转

    晓萌最近在做一个翻转图片的应用,你可能也知道,图片其实是由一个个的点组成的。于是,晓萌想先做一个可以翻转矩阵的程序,来解决他问题的核心部分。

    输入格式

    输入第一行包括由空格分开的整数 M,N,T(0 < N,M < 200)M,N,T(0<N,M<200),TT 的值为 00 或 11。其中 MM 和 NN 分别表示待处理矩阵的行数与列数,TT 为 00 时表示左右翻转,为 11 时表示上下翻转。

    之后的 MM 行,每行包括由空格分隔的 NN 个整数,依次为输入矩阵的每一行的数据。

    输出格式

    输出包括 MM 行 NN 列,每个数字之间用一个空格分隔,每一行行末均有一个空格,表示的是按照要求翻转后的矩阵。

    样例输入

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

    样例输出

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

    题解:分别讲i,j即行列交换顺序即可
     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <vector>
     6 #include <cstdlib>
     7 #include <iomanip>
     8 #include <cmath>
     9 #include <ctime>
    10 #include <map>
    11 #include <set>
    12 #include <queue>
    13 using namespace std;
    14 #define lowbit(x) (x&(-x))
    15 #define max(x,y) (x>y?x:y)
    16 #define min(x,y) (x<y?x:y)
    17 #define MAX 100000000000000000
    18 #define MOD 1000000007
    19 #define pi acos(-1.0)
    20 #define ei exp(1)
    21 #define PI 3.141592653589793238462
    22 #define INF 0x3f3f3f3f3f
    23 #define mem(a) (memset(a,0,sizeof(a)))
    24 typedef long long ll;
    25 ll gcd(ll a,ll b){
    26     return b?gcd(b,a%b):a;
    27 }
    28 bool cmp(int x,int y)
    29 {
    30     return x>y;
    31 }
    32 const int N=10005;
    33 int a[201][201];
    34 int main()
    35 {
    36     std::ios::sync_with_stdio(false);
    37     int n,m,t;
    38     cin>>n>>m>>t;
    39     for(int i=0;i<n;i++)
    40         for(int j=0;j<m;j++)
    41             cin>>a[i][j];
    42     if(t==1)
    43     for(int i=n-1;i>=0;i--){
    44         for(int j=0;j<m;j++)
    45             cout<<a[i][j]<<" ";
    46         cout<<endl;
    47     }
    48     else
    49     for(int i=0;i<n;i++){
    50         for(int j=m-1;j>=0;j--)
    51             cout<<a[i][j]<<" ";
    52         cout<<endl;
    53     }
    54     return 0;
    55 }
  • 相关阅读:
    使用 asp.net mvc和 jQuery UI 控件包
    ServiceStack.Redis 使用教程
    HTC T8878刷机手册
    Entity Framework CodeFirst 文章汇集
    2011年Mono发展历程
    日志管理实用程序LogExpert
    使用 NuGet 管理项目库
    WCF 4.0路由服务Routing Service
    精进不休 .NET 4.0 (1) asp.net 4.0 新特性之web.config的改进, ViewStateMode, ClientIDMode, EnablePersistedSelection, 控件的其它一些改进
    精进不休 .NET 4.0 (7) ADO.NET Entity Framework 4.0 新特性
  • 原文地址:https://www.cnblogs.com/wydxry/p/7275305.html
Copyright © 2011-2022 走看看