题目链接:https://vjudge.net/contest/345791#problem/L

【问题描述】

  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.

输入:

  The first line of input contains an integer NN (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 NN of the following characters (>, <, ∨, ∧ or .). Empty space is indicated by a '.' (dot).

输出:

  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.

样例输入:

3 R
>v>
...
<^<
3 L
>v>
...
<^<
3 LL
>v>
...
<^< 样例输出:
^.v
>.<
^.v
^.v
>.<
^.v
>v>
...
<^< 试题分析:
这是一道简单的模拟题,我们可以写出向左向右翻转的函数,然后直接遍历字符串即可。但这样会超时,可以进行优化,翻转周期为4,并且可以将左转转化为右转。
代码如下:
 #include<stdio.h>
#include<map>
#include<string.h>
const int MAXN = ;
using namespace std; int n;
char s[MAXN], ans[MAXN][MAXN], str[MAXN][MAXN];
map<char, char> mp; void move()
{
for(int col = ; col <= n; col ++)
for(int row = n; row >= ; row --)
ans[col][n - row + ] = mp[str[row][col]];
for(int i = ; i <= n; i ++)
for(int j = ; j <= n; j ++)
str[i][j] = ans[i][j];
} int main()
{
mp['>'] = 'v', mp['^'] = '>', mp['v'] = '<', mp['<'] = '^', mp['.'] = '.'; scanf("%d%s", &n, s);
getchar();
for(int i = ; i <= n; i ++)
scanf("%s", str[i] + );
for(int i = ; i <= n; i ++)
for(int j = ; j <= n; j ++)
ans[i][j] = str[i][j];
int len = strlen(s);
int rnum = , lnum = ;
for(int i = ; i < len; i ++)
{
if(s[i] == 'R')
rnum ++;
else
lnum ++;
}
if(rnum >= lnum)
{
rnum -= lnum;
rnum %= ;
}
else
{
lnum -= rnum;
lnum %= ;
rnum = - lnum;
rnum %= ;
}
for(int i = ; i <= rnum; i ++)
move();
for(int i = ; i <= n; i ++)
printf("%s\n", ans[i] + );
return ;
}

最新文章

  1. Error:No suitable device found: no device found for connection &quot;System eth0&quot;
  2. 【荐】Spring事务配置的五种方式
  3. logstash安装与基础用法
  4. sencha touch 入门系列 (二)sencha touch 开发准备
  5. iOS 中的UIWindow
  6. 【zabbix系列】报警系统的设置和排除
  7. 【WebKit】---WebKit的CSS扩展(WebKit是私有属性)
  8. websocket以及自定义协议编程一些总结
  9. jquery中DOM的操作方法
  10. Theano.tensor.round函数学习,同时解决输出Elemwise{xxx,no_inplace}.0的问题
  11. 怎么用JQUERY设置div背景图片?
  12. 项目启动失败,异常代码(StandardEngine[Catalina].StandardHost[localhost].StandardContext[/credit]]) ,dataSource 也报错
  13. vs2015 编译google v8
  14. mysql存储过程使用游标循环插入数据
  15. IBM ILOG JViews Charts 产品及功能介绍
  16. 数组名和数组名取地址&amp;
  17. 关于Filter中ServletRequest强转HttpServletRequest问题
  18. 什么是 AJAX ?
  19. Jmeter调度器配置
  20. HDU 1045 Fire Net 【连通块的压缩 二分图匹配】

热门文章

  1. mysql bigint与bigint unsigned
  2. [WEB安全]伪造IP地址进行爆破的BurpSuite插件:BurpFakeIP
  3. Centos7变动
  4. rsync 使用ssh协议免密
  5. JavaScript初探系列目录
  6. laravel修改了配置文件不生效,修改了数据库配置文件不生效
  7. vim 外部粘贴代码,如何保持原格式,而不持续缩进
  8. open jdk性能与稳定性测试比较(转载)
  9. Java static静态关键字 有啥用
  10. 各类型变量所占字节数,sizeof()