Cipher
Description
The length of the message is always less or equal than n. If the
message is shorter than n, then spaces are added to the end of the
message to get the message with the length n.
Help Alice and Bob and write program which reads the key and then a
sequence of pairs consisting of k and message to be encoded k times and
produces a list of encoded messages.
Input
input file consists of several blocks. Each block has a number 0 < n
<= 200 in the first line. The next line contains a sequence of n
numbers pairwise distinct and each greater than zero and less or equal
than n. Next lines contain integer number k and one message of ascii
characters separated by one space. The lines are ended with eol, this
eol does not belong to the message. The block ends with the separate
line with the number 0. After the last block there is in separate line
the number 0.
Output
is divided into blocks corresponding to the input blocks. Each block
contains the encoded input messages in the same order as in input file.
Each encoded message in the output file has the lenght n. After each
block there is one empty line.
Sample Input
10
4 5 3 7 2 8 1 6 10 9
1 Hello Bob
1995 CERC
0
0
Sample Output
BolHeol b
C RCE 题意 : Bob和Alice想用一种新的加密方式,他们编码和译码都是依靠秘密钥匙,秘密钥匙选用一串数字a1,……an(0<ai<=n),编码要求:将信息(长度不大于n,如果小于n请自己补上空格)中i位置上的字符放到ai位置上
。这个过程经过K遍之后就成了加密后的信息。现在要求你写一个程序帮他们实现编码。 思路: 因为K会很大, 暴力会超时, 将其看作一个置换群, 求出每个循环的长度, 可知一个循环的长度即他的周期; 考虑求出每个循环的长度L, 对K取模, 然后再暴力求解;
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
const int maxn= ; int main()
{
int n;
while(scanf("%d", &n) && n)
{
int hay[maxn], pos[maxn];
for(int i = ;i < n; i++)
{
scanf("%d",&hay[i]);
hay[i] -= ;
}
for(int i =;i < n;i++)
{
pos[i] = ;
int tmp = hay[i];
while(tmp!=i)
{
pos[i]++;
tmp = hay[tmp];
}
}
int k;
char s1[maxn], s2[maxn];
while(scanf("%d", &k) && k)
{
getchar();
gets(s1);
if(strlen(s1) < n)
{
for(int i = strlen(s1); i<n; i++)
s1[i] = ' ';
s1[n] = '\0';
}
for(int i = ; i < n; i++)
{
int tim = k%pos[i];
int t = i;
while(tim--)
{
t = hay[t];
}
s2[t] = s1[i];
}
s2[n] = '\0';
puts(s2);
}
printf("\n");
}
return ; }
Cipher的更多相关文章
- JAVA实现AES 解密报错Input length must be multiple of 16 when decrypting with padded cipher
加密代码 /**解密 * @param content 待解密内容 * @param password 解密密钥 * @return */ public static byte[] decrypt(b ...
- POJ1026 Cipher(置换的幂运算)
链接:http://poj.org/problem?id=1026 Cipher Time Limit: 1000MS Memory Limit: 10000K Total Submissions ...
- BZOJ 1031: [JSOI2007]字符加密Cipher 后缀数组
1031: [JSOI2007]字符加密Cipher Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 6014 Solved: 2503[Submit ...
- freeCodeCamp:Caesars Cipher
让上帝的归上帝,凯撒的归凯撒. 下面我们来介绍风靡全球的凯撒密码Caesar cipher,又叫移位密码. 移位密码也就是密码中的字母会按照指定的数量来做移位. 一个常见的案例就是ROT13密码,字母 ...
- ural Cipher Message
Cipher Message Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Desc ...
- 紫书例题-Ancient Cipher
Ancient Roman empire had a strong government system with various departments, including a secret ser ...
- 【BZOJ-1031】字符加密Cipher 后缀数组
1031: [JSOI2007]字符加密Cipher Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 5504 Solved: 2277[Submit ...
- uva-1339Ancient Cipher
Ancient Roman empire had a strong government system with various departments, including a secret ser ...
- scp使用加密算法报错unknown cipher type
为了提高scp的传输速度指定了scp的加密算法为arcfour $ scp -c arcfour localFile userName@remoteIP:remoteFile 得到报错unknown ...
- POJ - 1107 W's Cipher
POJ - 1107 W's Cipher Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u De ...
随机推荐
- 转:ActiveMQ的作用总结(应用场景及优势)
原文地址: ActiveMQ的作用总结(应用场景及优势) 业务场景说明: 消息队列在大型电子商务类网站,如京东.淘宝.去哪儿等网站有着深入的应用, 队列的主要作用是消除高并发访问高峰,加快网站的响应速 ...
- 50 行代码教你爬取猫眼电影 TOP100 榜所有信息
对于Python初学者来说,爬虫技能是应该是最好入门,也是最能够有让自己有成就感的,今天,恋习Python的手把手系列,手把手教你入门Python爬虫,爬取猫眼电影TOP100榜信息,将涉及到基础爬虫 ...
- pacakge-info.java
翻看以前的笔记,看到一个特殊的java文件:pacakge-info.java,虽然有记录,但是不全,就尝试着追踪一下该问题, 分享一下流水账式的结果. 首先,它不能随便被创建.在Eclipse中, ...
- mongodb和spring的整合
所需jar包 mongodb.xml文件代码
- Bootstrap3隐藏滑动侧边栏菜单代码特效
链接:https://pan.baidu.com/s/1syV3ZFg-RqfCv0HS5K0vug 提取码:yjex
- javascript面向对象中继承实现?
面向对象的基本特征有:封闭.继承.多态. 在javascript中实现继承的方法: 1.原型链(prototype chaining) 2.call()/apply() 3.混合方式(prototyp ...
- 20181220 Oracle程序包基本开发逻辑
做事情,开始也许比较迷茫,也可能工具不会,也可能语言不会,但不要害怕 多去思考而不是盲目的开始工作,盲目的听从,程序开发都是不断训练自己的思维能力. 做每件事情都是有意义的,思考为什么这么做,这么做的 ...
- 001-快速搭建Spring web应用【springboot 2.0.4】-gradle、springboot的启动过程分析、gradle多模块构建
一.概述 学习<精通Spring MVC4>书籍笔记 二.笔记 1.快速构建Spring starter web项目几种方式 1>使用Spring Tool Suite生成Start ...
- 自定义安装visual studio 2010开发asp.net
VS2010的安装对于VS的安装大家肯定都熟悉,不过我在很多地方看到的是大家讲VS的全部组件都安装了,不但浪费磁盘空间,还降低了系统性能,除此之外,还有人安装了VS之后不知道顺手把MSDN安装上,害得 ...
- NYOJ 棋盘覆盖
数字很大,要用大数乘法. #include<iostream> #include<stdio.h> #include<string.h> #include<q ...