1288 幸运转盘(一)

1288 幸运转盘(一)

题目描述

传说中每一个人都有一个幸运转盘,在人生的某些特殊时刻,
我们会在睡梦中(良好睡眠哦~)悄悄的转动自己的幸运转盘,
转盘的结果会影响着自己的心情,并改变自己的命运。
现在到你旋转幸运转盘的时候了,你有一个m*m的转盘,并且有t次机会转动它,
每一次转动,你可以选择它的转动方向,并让它相对于上一次转动一定的角度。
据说有一个角度是天使,看到天使的人一定会有好运的。
然而还有一个是恶魔角度,将给遇见他的人带来坏心情。

输入要求

第1行一个整数m(0< m <=20);
接下来m行,每行m个数字(0~9);
然后是一个整数t(0< t <=10);
接下来t行,每行包含2个整数x和y。
x表示转盘旋转的方向,值为0或1,0表示顺时针,1表示逆时针。
y在整型范围内,表示转盘要转过y(y<100000)个90角度。

输出要求

打印每一次旋转后的转盘视角布局,两组数据之间用空行分隔。

测试数据

//输入
3
1 2 3
4 5 6
7 8 9
2
0 1
1 2

//输出
7 4 1
8 5 2
9 6 3

3 6 9
2 5 8
1 4 7

AC代码

主要为了记录 = v =

#include <bits/stdc++.h>
using namespace std;
int a[25][25],temp[25][25],m,t,x,y,n,cnt=0;
void myreverse()
{
	int cnt=m-1;
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<m;j++) 
		{
			temp[j][cnt-i]=a[i][j];
		}
	}
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<m;j++) a[i][j]=temp[i][j];
	}
}
int main() {
	cin>>m;
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<m;j++) cin>>a[i][j];
	}
	cin>>t;
	while(t--)
	{
		if(cnt) cout<<endl;cnt++;
		cin>>x>>y;
		y=y%4;
		if(y==2) n=2;
		else if(x==0) n=y;
		else if(x==1) n=4-y;
		for(int i=0;i<n;i++) myreverse();
		for(int i=0;i<m;i++)
		{
			for(int j=0;j<m;j++) 
			{
				if(j) cout<<" ";
				cout<<a[i][j];
			}
			cout<<endl;
		}
	}
	return 0;
}
原文地址:https://www.cnblogs.com/xxhao/p/14318750.html