zoukankan      html  css  js  c++  java
  • BUPT复试专题—C翻转(2010)

    https://www.nowcoder.com/practice/74bdb725421c4f80b4aca7266818baf0?tpId=67&tqId=29639&rp=0&ru=/kaoyan/retest/1005&qru=/ta/bupt-kaoyan/question-ranking

    题目描述

    首先输入一个5 * 5的数组,然后输入一行,这一行有四个数,前两个代表操作类型,后两个数x y代表需操作数据为以x y为左上角的那几个数据。 操作类型有四种:  1 2 表示:90度,顺时针,翻转4个数  1 3 表示:90度,顺时针,翻转9个数  2 2 表示:90度,逆时针,翻转4个数  2 3 表示:90度,逆时针,翻转9个数 

    输入描述:

    输入有多组数据。
    每组输入一个5 * 5的数组,然后输入一行,这一行有四个数,前两个代表操作类型,后两个数x y代表需操作数据为以x y为左上角的那几个数据。

    输出描述:

    输出翻转后的数组。
    示例1

    输入

    1 2 3 4 5
    6 7 8 9 10
    11 12 13 14 15
    16 17 18 19 20
    21 22 23 24 25
    1 3 1 1

    输出

    11 6 1 4 5
    12 7 2 9 10
    13 8 3 14 15
    16 17 18 19 20
    21 22 23 24 25


    此题只有四种情况可以逐个来换序,如果更复杂再考虑其他关系
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<algorithm>
    #include<string.h>
    using namespace std;
    int a[10][10];
    void turn1(int x,int y)
    {
        int temp[10][10];
        temp[1][1]=a[x+2][y];temp[1][2]=a[x+1][y];temp[2][1]=a[x+2][y+1];temp[2][2]=a[x+1][y+1];
        temp[1][3]=a[x][y];temp[2][3]=a[x][y+1];temp[3][1]=a[x+2][y+2];temp[3][2]=a[x+1][y+2];temp[3][3]=a[x][y+2];
        a[x][y+2]=temp[1][3];a[x+1][y+2]=temp[2][3];a[x+2][y]=temp[3][1];a[x+2][y+1]=temp[3][2];a[x+2][y+2]=temp[3][3];
        a[x][y]=temp[1][1];a[x][y+1]=temp[1][2];a[x+1][y]=temp[2][1];a[x+1][y+1]=temp[2][2];
    }
    void turn2(int x,int y)
    {
        int temp[10][10];
        temp[1][1]=a[x][y+2];temp[1][2]=a[x+1][y+2];temp[2][1]=a[x][y+1];temp[2][2]=a[x+1][y+1];
        temp[1][3]=a[x+2][y+2];temp[2][3]=a[x+2][y+1];temp[3][1]=a[x][y];temp[3][2]=a[x+1][y];temp[3][3]=a[x+2][y];
        a[x][y+2]=temp[1][3];a[x+1][y+2]=temp[2][3];a[x+2][y]=temp[3][1];a[x+2][y+1]=temp[3][2];a[x+2][y+2]=temp[3][3];
        a[x][y]=temp[1][1];a[x][y+1]=temp[1][2];a[x+1][y]=temp[2][1];a[x+1][y+1]=temp[2][2];
    }
    void turn3(int x,int y)
    {
        int temp[10][10];
        temp[1][1]=a[x+1][y];temp[1][2]=a[x][y];temp[2][1]=a[x+1][y+1];temp[2][2]=a[x][y+1];
        a[x][y]=temp[1][1];a[x][y+1]=temp[1][2];a[x+1][y]=temp[2][1];a[x+1][y+1]=temp[2][2];
    }
    void turn4(int x,int y)
    {
        int temp[10][10];
        temp[1][1]=a[x][y+1];temp[1][2]=a[x+1][y+1];temp[2][1]=a[x][y];temp[2][2]=a[x+1][y];
        a[x][y]=temp[1][1];a[x][y+1]=temp[1][2];a[x+1][y]=temp[2][1];a[x+1][y+1]=temp[2][2];
    }
    int main()
    {
        while(scanf("%d %d %d %d %d",&a[0][0],&a[0][1],&a[0][2],&a[0][3],&a[0][4])!=EOF)
        {
            int num=1, m,n,x,y;
            while(num!=5)
            {
                scanf("%d %d %d %d %d",&a[num][0],&a[num][1],&a[num][2],&a[num][3],&a[num][4]);
                num++;
            }
            scanf("%d %d %d %d",&m,&n,&x,&y);
            if(n==3&&m==1)
            {
                turn1(x-1,y-1);
            }
            else if(n==3&&m==2)
            {
                turn2(x-1,y-1);
            }
            else if(n==2&&m==1)
            {
                turn3(x-1,y-1);
            }
            else if(n==2&&m==2)
            {
                turn4(x-1,y-1);
            }
            for(int i=0; i<5; i++)
            {
                for(int j=0; j<5; j++)
                {
                    cout<<a[i][j];
                    if(j<4)
                        cout<<" ";
                }
                cout<<endl;
            }
        }
        return 0;    
    }
  • 相关阅读:
    metal的gpu query
    体积雾 global fog unity 及改进
    hdr rt format对颜色的影响
    unity deferred lighting
    unity linear space时 photoshop blend的正确设置
    unity linear work flow
    一些数据 bandwidth之类
    deferred rendering with msaa
    unity 显示mipmaplevel
    【转】在C#中使用SendMessage
  • 原文地址:https://www.cnblogs.com/dzzy/p/8260667.html
Copyright © 2011-2022 走看看