Character Wheels
链接:https://ac.nowcoder.com/acm/contest/8688/I
来源:牛客网
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 524288K,其他语言1048576K
64bit IO Format: %lld
题目描述
You are given one n \times nn×n character wheels, and it is guaranteed that n is even. Please implement these following operations:
Clockwise/Counter-clockwise rotate the x-th wheel y(1≤y≤109 ) times. Rotating one time means rotatting 90 degrees. The instruction is L/R x y, R indicates rotating clockwise and L indicates rotating counter-clockwise. For example, R 1 3 means rotate the 1-st wheel 3 times clockwise.
Print all the wheels, the instruction is P.
输入描述
First line contains one integer 𝑛 ( 4 ≤ 𝑛 ≤ 50), indicates the size of the wheels.
Then followed the wheels.
After that, one line contains one integer 𝑚 ( 1 ≤ 𝑚 ≤ 100), indicates the number ofoperations.
Then followed 𝑚 lines, one line one instruction.
it is guaranteed that at least there is one P instruction and the wheels only contain lowercase letters.
输出描述
If the instruction is P, then print all the wheels.
题目大意
给一个n*n的矩阵,从外到内每一圈编号1~n/2,输入R就是向右转,L就是向左转,将第x圈旋转y次,每次旋转90°,注意题中要求y的次数小于10的九次方,因此需要y % 4 简化次数,避免超时
输入P打印当前矩阵
示例1
输入
4
abcd
cabe
fgha
edbe
5
L 1 1
P
R 1 3
L 2 1
P
输出
deae
cabb
bghd
acfe
ebde
abhf
eagc
dcba
思路
先把矩阵记录下来。
定义一个二位数组存入每个环的字符顺序。(均从一号位开始存入)a[环层数][0] 初始为0
之后根据具体旋转情况,改变a[环层数][0] 的 值。R1向右转加一,L1向左转减一。
输入P就将二维数组从新返回矩阵,将矩阵输出即可。
C++ 代码
#include<iostream>
#include<cstring>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int N = 10005;
char ma[55][55];
char a[55][N];
int n,T;
void print(){
for(int i = 1; i <= n/2; i ++)
{
int m = 1;
if(a[i][0] == '1'){
int hang = i,lie = i;
do{
ma[hang][lie] = a[i][m++]; lie ++;}while(m <= n - 2 * i + 1);
do{
ma[hang][lie] = a[i][m++]; hang++;}while(m <= 2*n - 4*i + 2);
do{
ma[hang][lie] = a[i][m++]