zoukankan      html  css  js  c++  java
  • 09:图像旋转翻转变换

    09:图像旋转翻转变换

    总时间限制: 
    1000ms
     
    内存限制: 
    65536kB
    描述

    给定m行n列的图像各像素点灰度值,对其依次进行一系列操作后,求最终图像。

    其中,可能的操作及对应字符有如下四种:

    A:顺时针旋转90度;

    B:逆时针旋转90度;

    C:左右翻转;

    D:上下翻转。

    输入
    第一行包含两个正整数m和n,表示图像的行数和列数,中间用单个空格隔开。1 <= m <= 100, 1 <= n <= 100。
    接下来m行,每行n个整数,表示图像中每个像素点的灰度值,相邻两个数之间用单个空格隔开。灰度值范围在0到255之间。
    接下来一行,包含由A、B、C、D组成的字符串s,表示需要按顺序执行的操作序列。s的长度在1到100之间。
    输出
    m'行,每行包含n'个整数,为最终图像各像素点的灰度值。其中m'为最终图像的行数,n'为最终图像的列数。相邻两个整数之间用单个空格隔开。
    样例输入
    2 3
    10 0 10
    100 100 10
    AC
    样例输出
    10 100
    0 100
    10 10

     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 #include<cmath>
     5 #include<queue>
     6 #include<vector>
     7 #include<algorithm>
     8 using namespace std;
     9 int n,m;
    10 int c[1001][1001];
    11 int b[1001][1001];
    12 char zx[101];
    13 void zh(char a)
    14 {
    15     if(a=='A')
    16     {
    17         for(int i=1;i<=n;i++)
    18         {
    19             for(int j=1;j<=m;j++)
    20             {
    21                 b[j][n-i+1]=c[i][j];
    22             }
    23         }
    24     }//顺时针旋转90度
    25     if(a=='B')
    26     {
    27         for(int i=1;i<=n;i++)
    28         {
    29             for(int j=1;j<=m;j++)
    30             {
    31                 b[m-j+1][i]=c[i][j];
    32             }
    33         }
    34     }//逆时针旋转90度
    35     if(a=='C')
    36     {
    37         for(int i=1;i<=n;i++)
    38         {
    39             for(int j=1;j<=m;j++)
    40             {
    41                 b[i][m-j+1]=c[i][j];
    42             }
    43         }
    44     }//左右翻转
    45     if(a=='D')
    46     {
    47         for(int i=1;i<=n;i++)
    48         {
    49             for(int j=1;j<=m;j++)
    50             {
    51                 b[n-i+1][j]=c[i][j];
    52             }
    53         }
    54     }//上下翻转
    55     memcpy(c,b,sizeof(c));
    56     if(a=='A'||a=='B')swap(m,n);
    57 }
    58 int main()
    59 {
    60     cin>>n>>m;
    61     for(int i=1;i<=n;i++)
    62     {
    63         for(int j=1;j<=m;j++)
    64         {
    65             cin>>c[i][j];
    66         }
    67     }
    68     scanf("%s",&zx);
    69     for(int i=0;i<strlen(zx);i++)
    70     {
    71         zh(zx[i]);
    72     }
    73     for(int i=1;i<=n;i++)
    74     {
    75         for(int j=1;j<=m;j++)
    76         {
    77             cout<<c[i][j]<<" ";
    78         }
    79         cout<<endl;
    80     }
    81     return 0;
    82 } 
  • 相关阅读:
    论文笔记系列-DARTS: Differentiable Architecture Search
    Win10安装TensorFlow1.9-GPU版本
    论文笔记系列-Efficient Neural Architecture Search via Parameter Sharing
    论文笔记模板
    无偏估计
    【TensorFlow】tf.nn.softmax_cross_entropy_with_logits的用法
    Python学习札记(十三) Function3 函数参数二
    LeetCode Add Two Numbers
    Python学习札记(十二) Function3 函数参数一
    Python学习札记(十一) Function2 函数定义
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/6523951.html
Copyright © 2011-2022 走看看