题目链接: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 ;
}

【作业】Mental Rotation (模拟)的更多相关文章

  1. C#基础第三天-作业-集合-冒泡排序-模拟名片

    1.名片:用两种集合(ArrayList/List<>)去输出余下信息.身份证号码,电话号码,性别,姓名,身高,年龄,体重.需求:根据 姓名 去查询某一行数据.如果集合中不存在提示(“自定 ...

  2. python开发基础作业01:模拟登陆系统

    随老男孩学习python mark 作业要求及提示:编写登录接口 ''' 练习程序:编写登录接口 1. 输入用户名和密码 2. 认证成功后显示欢迎信息 3. 输错三次后锁定 输入三次后退出,下次同样用 ...

  3. 从零开始学Python04作业思路:模拟ATM电子银行

    标签(空格分隔):Python 一,程序文件说明 程序分为5个组成部分 bin:放置Python程序的启动接口文件 通过Python命令启动文件夹内文件即正常执行Python程序 例如:ATM_sta ...

  4. 作业三:模拟 mysql 进行增删改查

    # !/usr/bin/env python3 # _*_coding:utf-8_*_ def help_sql(cmd): if cmd in func_dic.keys(): print('{} ...

  5. C#基础第三天-作业答案-集合-冒泡排序-模拟名片

    .冒泡排序 Console.WriteLine("对集合里的数进行排序,请输入第一个数:"); int a = int.Parse(Console.ReadLine()); Con ...

  6. python作业模拟计算器开发(第五周)

    作业需求: 模拟计算器开发: 实现加减乘除及拓号优先级解析 用户输入 1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/1 ...

  7. day4作业模拟实现一个ATM + 购物商城程序

    作业需求: 模拟实现一个ATM + 购物商城程序 1.额度 15000或自定义: 2.实现购物商城,买东西加入 购物车,调用信用卡接口结账: 3.可以提现,手续费5%: 4.每月22号出账单,每月10 ...

  8. SQL Server代理(10/12):使用代理账号运行作业

    SQL Server代理是所有实时数据库的核心.代理有很多不明显的用法,因此系统的知识,对于开发人员还是DBA都是有用的.这系列文章会通俗介绍它的很多用法. 在这一系列的上一篇,你查看了msdb库下用 ...

  9. SQL Server代理(9/12):理解作业和安全

    SQL Server代理是所有实时数据库的核心.代理有很多不明显的用法,因此系统的知识,对于开发人员还是DBA都是有用的.这系列文章会通俗介绍它的很多用法. 在这个系列的前一篇文章里,你学习了如何在S ...

随机推荐

  1. 35、sparkSQL及DataFrame

    一.saprkSQL背景 Spark 1.0版本开始,推出了Spark SQL.其实最早使用的,都是Hadoop自己的Hive查询引擎:但是后来Spark提供了Shark:再后来Shark被淘汰,推出 ...

  2. Codeforces 1172F Nauuo and Bug [线段树]

    Codeforces 思路 定义\(f_{l,r}(x)\)表示数\(x\)从\(l\)进去\(r\)出来的时候会变成什么样子.容易发现这个函数是个分段函数,每一段都是斜率为1的一次函数,并且段数就是 ...

  3. 贪心算法训练(九)——Best Cow Line(字典序最小问题)

    原题链接:Best Cow Line 1. 问题描述 2. 输入 6 A C D B C B 3. 输出 ABCBCD 4.思路分析 不断地取原字符串 S 中开头和末尾比较小的字符串放到 T 的末尾 ...

  4. Java ArrayList几种遍历方法

    import java.util.ArrayList; import java.util.Iterator; public class StringSampleDemo { public static ...

  5. NOIP(划掉)CSP2019一轮知识点

    今年似乎变动很大呢…… 去年总结的 历年真题 以下标题中打*的是我认为的重点内容 *一.关于计算机 (一)计算机组成 计算机的工作原理跟人的大脑很相似,而且还是大脑功能的延伸,所以习惯上叫它电脑. 硬 ...

  6. docker本地仓库&镜像

    镜像的命名规则: 1.[冷数据]/[base镜像]例如:ansible,centos 2. lastest{最新的意思}  不是真的(随便命名) 3. [image name]=[repository ...

  7. spark-shell启动错误

    18/06/24 16:41:40 ERROR spark.SparkContext: Error initializing SparkContext.java.net.BindException: ...

  8. Oracle语法 及 SQL题目(三)

    目录 SQL题目六 第一个问题思路(查询酒类商品的总点击量) 第二个问题思路(查询每个类别所属商品的总点击量,并按降序排列) 第三个问题思路(查询所有类别中最热门的品种(点击量最高),并按点击量降顺序 ...

  9. YARN 状态机可视化,生成状态机图

    由于在windows下面,配置好所有 编译hadoop2.4.1源码 的环境会很麻烦,好在我之前已经把hadoop2.4.1的源码成功导入eclipse,并解决了所有错误提示,所以我就可以在eclip ...

  10. [电脑]拆解DELL 2007FPb液晶显示器

    最近修了不少三星214T显示器,拆卸很方便,多数更换电容就OK了.但有一台出现了花屏,怀疑是数码板出问题了.单位有台显示屏破碎的DELL2007FPb,拆了看看能否借用数码板. 图片:IMG_2063 ...