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

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

题目链接

#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;
}

猜你喜欢

转载自blog.csdn.net/wzazzy/article/details/81712492