2018 杭电多校训练 8 Magic Square (hdu 6401)

本文详细解析了一道使用C++进行矩阵操作的模拟题,包括读取输入、矩阵旋转和输出结果的过程。通过具体实例,展示了如何利用C++标准库进行矩阵元素的读取、旋转和打印,适合初学者理解和掌握矩阵操作的基本技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这是这次的签到题 模拟。。。

题目链接

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>

#define INF 0x3f3f3f3f
#define maxn 10
#define mod 1e9+7;
#define ll long long int

using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;cin>>t;
    while(t--)
    {
        int n;cin>>n;
        int map[maxn][maxn];
        int a,b,c;cin>>a>>b>>c;
        map[0][0]=a/100;map[0][1]=a%100/10;map[0][2]=a%100%10;
        map[1][0]=b/100;map[1][1]=b%100/10;map[1][2]=b%100%10;
        map[2][0]=c/100;map[2][1]=c%100/10;map[2][2]=c%100%10;
        while(n--)
        {
            string a;cin>>a;
            if(a[0]=='1')
            {
                if(a[1]=='C')
                {
                    int temp=map[0][0];
                    map[0][0]=map[1][0];
                    map[1][0]=map[1][1];
                    map[1][1]=map[0][1];
                    map[0][1]=temp;
                }
                if(a[1]=='R')
                {
                    int temp=map[0][0];
                    map[0][0]=map[0][1];
                    map[0][1]=map[1][1];
                    map[1][1]=map[1][0];
                    map[1][0]=temp;
                }
            }
            if(a[0]=='2')
            {
                if(a[1]=='C')
                {
                    int temp=map[0][1];
                    map[0][1]=map[1][1];
                    map[1][1]=map[1][2];
                    map[1][2]=map[0][2];
                    map[0][2]=temp;
                }
                if(a[1]=='R')
                {
                    int temp=map[0][1];
                    map[0][1]=map[0][2];
                    map[0][2]=map[1][2];
                    map[1][2]=map[1][1];
                    map[1][1]=temp;
                }
            }
            if(a[0]=='3')
            {
                if(a[1]=='C')
                {
                    int temp=map[1][0];
                    map[1][0]=map[2][0];
                    map[2][0]=map[2][1];
                    map[2][1]=map[1][1];
                    map[1][1]=temp;
                }
                if(a[1]=='R')
                {
                    int temp=map[1][0];
                    map[1][0]=map[1][1];
                    map[1][1]=map[2][1];
                    map[2][1]=map[2][0];
                    map[2][0]=temp;
                }
            }
            if(a[0]=='4')
            {
                if(a[1]=='C')
                {
                    int temp=map[1][1];
                    map[1][1]=map[2][1];
                    map[2][1]=map[2][2];
                    map[2][2]=map[1][2];
                    map[1][2]=temp;
                }
                if(a[1]=='R')
                {
                    int temp=map[1][1];
                    map[1][1]=map[1][2];
                    map[1][2]=map[2][2];
                    map[2][2]=map[2][1];
                    map[2][1]=temp;
                }
            }
        }
        for(int i=0;i<3;i++)
        {
            for(int j=0;j<3;j++)
            {
                cout<<map[i][j];
            }
            cout<<endl;
        }
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值