当前位置: 首页 > news >正文

春季赛day15 Snailography

题目描述

Snails have many enemies including snakes, turtles, and birds. So, snails need to communicate their travel paths using cryptography to avoid their routes being detected. 

The encryption technique: The message will contain only letters. Let’s assume the message length is L. We use the smallest odd integer N such that N×N ≥ L. Then, an N×N table is used to encrypt the message as follows: 
Put the first letter of the message in the cell at the center of the table and then put the remaining letters in the table by moving in a circular way (snail like) around the center cell. 
For example, the table to the right shows the order for placing the letters from the message in a 7×7 table. So, from the center cell, we move up, then move right, then move down, then move left, then move up, etc. 
Below are some sample encryptions. To help with the illustrations, when encrypting the message, if there are more cells in the table than there are letters in the message, we put the character ‘#’ in the extra cells. 
Message: ABCDEFGH
Encryption: 
#BC
HAD
GFE
Message: ABCDEFGHIJKLMNOPQRSTUVW
Encryption: 
#JKLM
#IBCN
WHADO
VGFEP
UTSRQ
Message: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv
Encryption: 
#Zabcde
vYJKLMf
uXIBCNg
tWHADOh
sVGFEPi
rUTSRQj
qponmlk

Given the size of the two-dimensional table to use and the original message, you are to encrypt the message (to help snails live longer lives).

输入

The first input line contains an odd integer, n (1 ≤ n ≤ 19), indicating the table size to use. The second input line will provide the message to encrypt, a string of 1-361 (19×19) letters (lowercase and uppercase). Assume that the message will fit in the table. 

输出

Print the encrypted message on one output line using the row-major order, i.e., print Row 1 followed by Row 2, followed by Row 3, etc. 
Remember to print a newline character after printing the last row. 
The output should not include ‘#’ characters.

样例输入 Copy
【样例1】
3 
ABCDEFGH
【样例2】
5 
ABCDEFGHIJKLMNOPQRSTUVW
样例输出 Copy
【样例1】
BCHADGFE
【样例2】
JKLMIBCNWHADOVGFEPUTSRQ

填表的时候注意每一次操作填满的话下一次操作的开头不能直接从尾巴开始(不然会重复填一个格子)

代码 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
char tab[21][21];
string s;

void fill(int x,int y,int start,int len){
	if(start>=s.length())return;
	int p=start;
	for(int i=y;i<y+len-2;++i){tab[x][i]=s[p++];if(p==s.length())return;}	
	for(int i=x;i<x+len-1;++i){tab[i][y+len-2]=s[p++];if(p==s.length())return;}
	for(int i=y+len-2;i>y-1;--i){tab[x+len-1][i]=s[p++];if(p==s.length())return;}
	for(int i=x+len-1;i>=x;--i){tab[i][y-1]=s[p++];if(p==s.length())return;}
	fill(x-1,y-1,p,len+2);
}
int main(){
	cin>>n>>s;
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j)tab[i][j]='#';
	}
	tab[n/2][n/2]=s[0];
	fill(n/2-1,n/2,1,3);
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			if(tab[i][j]!='#')cout<<tab[i][j];
		}
	}
	return 0;
}

http://www.dtcms.com/a/113763.html

相关文章:

  • 铁电液晶(FLC)与反铁电液晶(AFLC)
  • SCADE One - 弥合基于模型设计与传统编程之间的鸿沟
  • 【学Rust写CAD】31 muldiv255函数(muldiv255.rs)
  • 设计模式简述(三)工厂模式
  • 《C语言代码解析与应用:数组操作的两种实现》
  • ctfshow VIP题目限免 版本控制泄露源码2
  • LeetCode详解之如何一步步优化到最佳解法:20. 有效的括号
  • 配置ASP.NET Core+NLog配置日志示例
  • 基于 FPGA 的分秒计数器
  • 如何实现两个视频融合EasyCVR平台的数据同步?详细步骤指南
  • 爬虫练习案例
  • zk基础—5.Curator的使用与剖析二
  • 打造高效英文单词记忆系统:基于Python的实现与分析
  • $R^n$超平面约束下的向量列
  • 游戏引擎学习第206天
  • React框架的Hooks实现原理
  • MicroPython 开发ESP32应用教程 之 WIFI简单应用 :时间同步、天气信息获取,ST7735 TFT屏驱动及任意中文字符显示
  • Linux制作deb安装包
  • 卡尔曼滤波器浅聊
  • windows 常用命令总结
  • MySQL表的增删改查基础版
  • 【大模型深度学习】如何估算大模型需要的显存
  • JavaScript基础--09-流程控制语句:选择结构(if和switch)
  • 文件系统-inode/软硬件连接(未完结)
  • 用 Python 制作仓库自动化指南
  • Kotlin协程机制
  • 解析keras.layers.Layer中的权重参数
  • Linux内核——段描述符详解
  • SeaTunnel系列之:Apache SeaTunnel编译和安装
  • 《SQL赋能人工智能:解锁特征工程的隐秘力量》