zoukankan      html  css  js  c++  java
  • 1171.C翻转

    题目描述:

    首先输入一个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 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>
    using namespace std; //这个取地址66666!!! 
    
    void transform1(int *a){
        int temp=*a;
        *a=*(a+5);
        *(a+5)=*(a+6);
        *(a+6)=*(a+1);
        *(a+1)=temp;
    }
    
    void transform2(int *a){
        int da=*a;
        *a=*(a+10);
        *(a+10)=*(a+12);
        *(a+12)=*(a+2);
        *(a+2)=da;
         
        da=*(a+1);
        *(a+1)=*(a+5);
        *(a+5)=*(a+11);
        *(a+11)=*(a+7);
        *(a+7)=da;  }
    
    void transform3(int *a){
        int temp=*a;
        *a=*(a+1);
        *(a+1)=*(a+6);
        *(a+6)=*(a+5);
        *(a+5)=temp;
    }
    
    void transform4(int *a){
        int da=*a;
        *a=*(a+2);
        *(a+2)=*(a+12);
        *(a+12)=*(a+10);
        *(a+10)=da;
         
        da=*(a+1);
        *(a+1)=*(a+7);
        *(a+7)=*(a+11);
        *(a+11)=*(a+5);
        *(a+5)=da;  
    }
    
    int main(){
        int a[5][5];
        int f1,f2,i,j,x,y;
        while(cin>>a[0][0]>>a[0][1]>>a[0][2]>>a[0][3]>>a[0][4]){
            for(i=1;i<5;i++){
                for(j=0;j<5;j++)
                {
                    cin>>a[i][j];
                }
            }
            cin>>f1>>f2>>x>>y;
            x--;
            y--;
            if(f1==1 && f2==2){
                transform1(&a[x][y]);
            }
            else if(f1==1 && f2==3){
                transform2(&a[x][y]);
            }
            else if(f1==2 && f2==2){
                transform3(&a[x][y]);
            }
            else {
                transform4(&a[x][y]);
            }
        }
        for(i=0;i<5;i++){
            for(j=0;j<5;j++)
            {
                if(j==0) cout<<a[i][j];
                 else cout<<" "<<a[i][j];
            }
            cout<<endl;
        }
        return 0;
    }
  • 相关阅读:
    使用NetHogs监控进程网络使用情况
    ssh连接超慢解决
    Dnsmasq安装与配置-搭建本地DNS服务器
    解决rpm conflicts with file from package的两个方法
    shell中的crontab定时任务
    hive函数大全
    hive的高级查询(group by、 order by、 join 、 distribute by、sort by、 clusrer by、 union all等)
    sql中的case when then else end
    hive向表格中插入数据并分析语句
    将数据导入hive,再将hive表导入hbase
  • 原文地址:https://www.cnblogs.com/bernieloveslife/p/9735159.html
Copyright © 2011-2022 走看看