2020ICPC亚洲网上区域赛模拟赛I题Character Wheels(模拟题)

文章目录Character Wheels题目描述输入描述输出描述题目大意示例1输入输出思路C++ 代码Character Wheels链接:https://ac.nowcoder.com/acm/contest/8688/I来源:牛客网时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 524288K,其他语言1048576K64bit IO Format: %lld题目描述You are given one n \times nn×n character wheels, and
摘要由CSDN通过智能技术生成

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++]
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值