zoukankan      html  css  js  c++  java
  • BUPT复试专题—旋转图像(2014)

    题目描述

    将一幅只含有01像素点的图片进行顺时针旋转,旋转的角度仅包含0°,90°,180°,270°

    输入

    第一行一个整数T(<50)表示输入的组数

    每组测试数据第一行是两个整数N和M(<50)表示图片的高度和宽度

    接下来N行,每行是一个01串,表示图像的像素点

    最后一行是旋转的角度

    输出

    输出旋转后的图片,不要输出空余的空格

    样例输入

    2
    2 3
    111
    000
    90
    3 3
    111
    101
    111
    180

    样例输出

    01
    01
    01
    111
    101
    111

    来源

    2014机考B题   转载请注明出处

    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<cmath>
    using namespace std;
    int main()
    {
        int n,t,m,p;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d %d",&m,&n);
            string dl;
            bool d[51][51],temp[51][51];
            for(int i=0;i<m;i++)
            {
                cin>>dl;
                for(int j=0;j<n;j++)
                {
                    d[i][j]=dl[j]-'0';
                }
            }
            scanf("%d",&p);
            if(p==0)
            {
                for(int i=0;i<m;i++)
                {
                    for(int j=0;j<n;j++)
                    {
                        cout<<d[i][j];
                    }
                    cout<<endl;
                }
            }
            if(p==90)
            {
                for(int i=0;i<m;i++)
                {
                    for(int j=0;j<n;j++)
                    {
                        temp[j][m-1-i]=d[i][j];
                    }
                }
                for(int i=0;i<n;i++)
                {
                    for(int j=0;j<m;j++)
                    {
                        cout<<temp[i][j];
                    }
                    cout<<endl;
                }
            }
            else if(p==180)
            {
                for(int i=m-1;i>=0;i--)
                {
                    for(int j=n-1;j>=0;j--)
                    {
                        cout<<d[i][j];
                    }
                    cout<<endl;
                }
            }
            else if(p==270)
            {
                for(int i=0;i<m;i++)
                {
                    for(int j=0;j<n;j++)
                    {
                        temp[n-1-j][i]=d[i][j];
                    }
                }
                for(int i=0;i<n;i++)
                {
                    for(int j=0;j<m;j++)
                    {
                        cout<<temp[i][j];
                    }
                    cout<<endl;
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    AFNetwork 作用和用法详解
    ios 常见错误记录
    UIView的setNeedsLayout, layoutIfNeeded 和 layoutSubviews 方法之间的关系解释
    AutoLayout
    矩阵的法式
    极小多项式
    对角化
    线性映射
    线性方程组的解
    特征值和特征向量
  • 原文地址:https://www.cnblogs.com/dzzy/p/8504868.html
Copyright © 2011-2022 走看看