题目链接:http://codeforces.com/gym/102219/problem/A
Time limit per test 1.0 s Memory limit per test 256 MB
Description
Mental rotation is a difficult thing to master. Mental rotation is the ability to imagine in your mind how an object would look like from a viewer's side if you were to rotate it in a particular direction. It is something very important for engineers to learn and master, especially if you are required to do engineering drawing. There are many stages to these mental rotation tasks. We will approach a simple rotation task in this problem.
If you are given the following square -
After rotating it to the right once, it will look like the following -
After rotating it to the left once, it will look like the following -
For this problem you will be given an initial square of size n and a list of rotations to perform.
Your task is to output the final representation of the square after performing all the rotation.
Input
The first line of input contains an integer N (1 ≤ N ≤ 1000). and a string containing a combination of ′L′ and ′R′. Where ′L′ means left rotation and ′R′ means right rotation. Length of the string will not exceed 100. Starting from the second line, the following N line each will contain N of the following characters (>, <, ∨, ∧ or .). Empty space is indicated by a '.' (dot).
Output
The output should be N lines, each containing N characters representing the final representation of the square after all the rotation. For ∨ and ∧ use v (small v) and Shift+6 respectively.
Examples
input
3 R
>v>
...
<^<
output
^.v
>.<
^.v
input
3 L
>v>
...
<^<
output
^.v
>.<
^.v
input
3 LL
>v>
...
<^<
output
>v>
...
<^<
Problem solving report:
Description: 给你一个n*n的矩阵和一行命令L代表逆时针旋转,R代表顺时针旋转,求最终的图形是什么。
Problem solving: 直接模拟就行了。
Accepted Code:
/*
* @Author: lzyws739307453
* @Language: C++
*/
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
const int MAXM = 105;
char s[MAXM], str[MAXN][MAXN], str_[MAXN][MAXN];
char Trans(char str) {
switch (str) {
case '>': return 'v';
case 'v': return '<';
case '<': return '^';
case '^': return '>';
}
return '.';
}
int main() {
int n, l = 0, r = 0;
scanf("%d%s", &n, s);
for (int i = 0; i < n; i++)
scanf("%s", str[i]);
for (int i = 0; s[i]; i++) {
if (s[i] != 'R')
l++;
else r++;
}
r %= 4, l %= 4;
r = (r - l + 4) % 4;
while (r--) {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
str_[i][j] = Trans(str[n - 1 - j][i]);
memcpy(str, str_, sizeof(str_));
}
for (int i = 0; i < n; i++)
printf("%s\n", str[i]);
return 0;
}