ZOJ1006 Do the Untwist

opencv3 feature2d 的探索 想研究一下 feature.cpp中的detect() virtual void cv::Feature2D::detect ( InputArray image, std::vector< KeyPoint > & keypoints, ... 阅读详情

                                                                                   ZOJ1006 Do the Untwist

Time Limit: 2000 msMemory Limit: 65536 KB

Cryptography deals with methods of secret communication that transform a message (the plaintext) into a disguised form (the ciphertext) so that no one seeing the ciphertext will be able to figure out the plaintext except the intended recipient. Transforming the plaintext to the ciphertext is encryption; transforming the ciphertext to the plaintext is decryption. Twisting is a simple encryption method that requires that the sender and recipient both agree on a secret key k, which is a positive integer.

The twisting method uses four arrays: plaintext and ciphertext are arrays of characters, and plaincode and ciphercode are arrays of integers. All arrays are of length n, where n is the length of the message to be encrypted. Arrays are origin zero, so the elements are numbered from 0 to n - 1. For this problem all messages will contain only lowercase letters, the period, and the underscore (representing a space).

The message to be encrypted is stored in plaintext. Given a key k, the encryption method works as follows. First convert the letters in plaintext to integer codes in plaincode according to the following rule: '_' = 0, 'a' = 1, 'b' = 2, ..., 'z' = 26, and '.' = 27. Next, convert each code in plaincode to an encrypted code in ciphercode according to the following formula: for all i from 0 to n - 1,

ciphercode[i] = (plaincode[ki mod n] - i) mod 28.

(Here x mod y is the positive remainder when x is divided by y. For example, 3 mod 7 = 3, 22 mod 8 = 6, and -1 mod 28 = 27. You can use the C '%' operator or Pascal 'mod' operator to compute this as long as you add y if the result is negative.) Finally, convert the codes in ciphercode back to letters in ciphertextaccording to the rule listed above. The final twisted message is in ciphertext. Twisting the message cat using the key 5 yields the following:

 

Array012
plaintext'c''a''t'
plaincode3120
ciphercode31927
ciphertext'c''s''.'

Your task is to write a program that can untwist messages, i.e., convert the ciphertext back to the original plaintext given the key k. For example, given the key 5 and ciphertext 'cs.', your program must output the plaintext 'cat'.

The input file contains one or more test cases, followed by a line containing only the number 0 that signals the end of the file. Each test case is on a line by itself and consists of the key k, a space, and then a twisted message containing at least one and at most 70 characters. The key k will be a positive integer not greater than 300. For each test case, output the untwisted message on a line by itself.

Note: you can assume that untwisting a message always yields a unique result. (For those of you with some knowledge of basic number theory or abstract algebra, this will be the case provided that the greatest common divisor of the key k and length n is 1, which it will be for all test cases.)

Example input:

5 cs.
101 thqqxw.lui.qswer
3 b_ylxmhzjsys.virpbkr
0

Example output:

cat
this_is_a_secret
beware._dogs_barking
#include <cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
using namespace std;
int main()
{
    string s;
    while(cin>>s){
        string x;
        if(s=="zoj"){
            cout<<"Accepted"<<endl;
            continue;
        }
        int i=0;
        int tz=-1,tj=-1;
        for(;i<s.length();i++){
            if(s[i]=='z'&&tz==-1){
                tz=i;
            }
            else{
                if(s[i]=='j'&&tj==-1){
                    tj=i;
                }
            }
        }
        int num=tj-tz-1;
        if(num>0){
            x=s.substr(0,tz);            
            string s1=x+'z';
            for(i=0;i<num;i++){
                s1+='o';
            }
            s1+='j';
            for(i=0;i<num;i++){
                s1+=x;
            }
            if(s1==s){
                cout<<"Accepted"<<endl;
                continue;
            }
        }
        cout<<"Wrong Answer"<<endl;
    }
    return 0;
}

Java压缩与解压缩ZIP文件 小而美的使用JDK自带的ZIP工具包生成与解压缩ZIP文件 阅读详情

相关推荐

mysslstrip:CVE-2015-3152 PoC

单条 mysslstrip 是一个基于 Python 的概念验证,展示了如何根据来 MITM MySQL 流量和剥离 SSL/TLS。 用法 mysslstrip.py [-h] [-p LISTEN_PORT] [-i LISTEN_INTERFACE] dest 示例输出 [root@duo1 ~]# python2.7 mysslstrip.py -p 3307 127.0.0.1:3306 2015-04-29 21:33:14+0000 [-] Log opened. 2015-04-29 21:33:14+0000 [-] listen: 127.0.0.1:3307; connect: 127.0.0.1:3306 2015-04-29 21:33:14+0000 [-] MySQLForwardServerFactory starting on 3307 2015-04

java解压zip压缩包

java 解压压缩包,java 实现解压 zip 压缩包。坐在旁边的小伙伴问我怎么用 java 将服务器上的压缩文件解压出来,我索引给他写了个 demo ,也顺手记录一下。

yuhuofei的草屋 1万+

区块链技术在碳足迹数据存证与溯源中的应用深度解析

消费者扫描产品上的二维码,即可通过区块链浏览器查询到该产品的数字碳标签,并追溯其从茶园到货架的每一步碳足迹数据,以及这些数据是如何被智能合约自动计算和认证的,从而建立起强大的品牌信任。如果说哈希链解决了数据的“存”与“证”的问题,那么智能合约则解决了数据“用”与“管”的自动化问题。综上所述,虽然针对“碳足迹数据可追溯性”这一特定应用场景的公开、标准化的性能基准案例尚不丰富,但现有研究和企业级解决方案(特别是联盟链)已经证明,通过合理的技术选型和架构设计,区块链的性能可以满足实际商业需求。

百态·数智思维 | 聚焦大数据、量化与未来AI 1107

[Ubuntu] Access denied for user ‘debian-sys-maint’@‘localhost’ (using password: YES)

问题描述: 在ubuntu 16.04上安装了mysql,在启动mysql的时候,出现了如下错误: mysqladmin: connect to service mysql at 'localhost' failed error: 'Access denied for user 'debian-sys-maint'@'localhost' (using password: YES)' 解决方案: 通过一番尝试推测问题出现的原因:出现这个问题的原因是由于debian拥有一个控制用户打开/关闭和检

烟雨天青色 4364

EndNote全文检索实战:如何快速配置学校图书馆资源并精准查找文献

本文详细介绍了EndNote全文检索功能的实战配置方法,核心在于通过正确设置OpenURL链接解析器,无缝对接学校图书馆资源,实现一键精准获取文献全文。文章提供了从理解机制、四步配置法到进阶技巧的完整指南,帮助科研人员高效管理海量PDF,构建个人知识体系,大幅提升文献调研与写作效率。

weixin_29228781的博客 280

Qt版Dalsa线扫相机的采集Demo

Qt Dalsa

追赶时代的博客 606

zoj 1006 do the untwist

题目见zoj 1006 或poj 1317  简单的解密算法,直接套用题目中公式即可。   /* zoj 1006 Do the Untwist */ #include &lt;stdio.h&gt; #include &lt;string.h&gt; #define MAXLEN 80 #define MAGICNUM 28 char num2Char(int ...

codeprac 198

黑猫带你学eMMC协议第17篇:超详细的eMMC HS200 & HS400讲解

1 前言 1.1 声明 本文依据eMMC JEDEC5.1及个人工作经验整理而成,如有错误请留言。 本文结合eMMC JEDEC5.1协议手册查看效果更佳。 1.2 内容提要 本文大约6000字,主要内容有: 1.什么是emmc hs200/hs400? 2.什么是tuning?tuning的过程又是什么? 3.如何设置才能让emmc进入hs200 mode? 4.如何设置才能让emmc进入hs400 mode? 5.emmc关于HS200/HS400内部结构框图对比。 6.部分个人相关经验总结。

黑猫奥利奥的博客 1万+

ZOJ-1006-Do the Untwist

这道题没什么好说的,非常简单,虽然是密码相关,但是给出了翔实的背景和过程,唯一需要动一点脑的地方就是从题目中公式里求余的结果得到原数。由于懒得再写一个和这个程序相反的加密程序,所以只用了sample数据试了一下,一看没错,就提交了,这回一次就AC了,不过我发现我的程序用的memory都在800多k,也不知道那些只用了300或400k的人是怎么弄的。

outer of the space 2518

华为OD机试 - 打印机队列 - 优先队列(Python/JS/C/C++ 双机位C卷 200分)

这个问题要求模拟打印机的文件调度过程,关键在于正确处理每个打印机队列中的文件优先级和文件进入队列的顺序。优先级处理:每个文件有一个 1 到 10 的优先级,数字越大优先级越高,打印机应首先处理优先级最高的文件。在打印机 1 的队列中插入了 3 个文件,分别有不同的优先级,其中编号 3 的文件优先级最高,先被取出。因为打印的文件内容有轻重缓急之分,所以队列中的文件有1~10 不同的 优先级,其中数字越大优先级越高。在打印机 2 的队列中插入了 1 个文件,优先级为 1,因此它被首先取出。

学Java,找哪吒 1080

如何正确理解和获取S参数

差分四端口的S参数是由双端口S参数逐步演化而来,因此,在数学中,其各分量均可以从单端S参数推导而来,在实际的仿真和测试中,软件和测量设备也是通过获取单端S参数矩阵再进行运算得到混合S参数矩阵的,并非直接获取。

一只豌豆象的博客 5154

ZOJ 1006 Do the Untwist

密码学涉及将消息(明文)转化为伪装形式(密文)的方法,以便除预定接收者外,没有人能够从密文中推测出明文。对于每个测试用例,输出解密后的明文,每个测试用例的输出占一行。(一个整数),一个空格,以及一个包含至少一个字符、最多 70 个字符的扭曲消息。是待加密消息的长度。数组的索引从 0 开始,所以元素的编号从 0 到。你的任务是编写一个程序,将密文解密,返回原始的明文,给定密钥。是一种简单的加密方法,要求发送方和接收方都同意一个秘密密钥。对于每个测试用例,输出解密后的明文。中的每个代码转换为加密后的代码。

wuqingshun314159的博客 401

SAP Gateway 故障排查全景图:从 Error Log 到 E2E 追踪,一套面向实战的工具与方法论

本文针对SAP Gateway Foundation(SAP_GWFND)的故障排查需求,梳理了从现象到根因的系统化排查路径。文章首先强调建立标准化排障流程的重要性,随后提供工具矩阵及使用顺序指引:对于请求中断优先查看Error Log(/IWFND/ERROR_LOG和/IWBEP/ERROR_LOG),性能问题使用Performance Trace(/IWFND/TRACES),通知异常则检查Notification Monitor。重点工具包括: Error Log作为中断类错误首要定位器; Appl

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 249

ZOJ--1006:Do the Untwist

Do the Untwist Time Limit: 2 Seconds      Memory Limit: 65536 KB Cryptography deals with methods of secret communication that transform a message (the plaintext) into a disguised form (the c

yf224的博客 406

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

ZOJ Problem Set - 1006 Do the Untwist

Do the Untwist Time Limit: 2 Seconds      Memory Limit: 65536 KB Cryptography deals with methods of secret communication that transform a message (the plaintext) into a disguised form (the c

Just The Way You Are 620

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

ZOJ1006-Do the Untwist

#include #include char plaintext[72]; char ciphertext[72]; int plaincode[72]; int ciphercode[72]; int k; unsigned long n; void decrypt() { for (int i = 0; i < n; i++) { if (plaincode[i

Collider 428

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

ZOJ Problem Set - 1006 Do the Untwist

ZOJ Problem Set - 1006 Do the Untwist Time Limit: 2 Seconds                                     Memory Limit: 65536 KB                             Cryptography deals with methods of secret

Jackwuyongxing的专栏 772

ZOJ-1006- Do the Untwist

#include <stdio.h> #include <string.h> //加密过程 //plaintext-->plaincode-->cyphercode-->cyphertext //ciphercode[i]=(plaincode[(k*i)%n]-i)mod 28(题目已知) //解密过程就是加密的逆过程 //cyphertext--&...

lengyudota的博客 224

ZOJ Problem Set - 1006 Do the Untwist

ZOJ Problem Set - 1006 Do the Untwist

My world 707

ZOJ Problem Set - 1006 Do the Untwist

Do the Untwist Time Limit: 2 Seconds      Memory Limit: 65536 KB Cryptography deals with methods of secret communication that transform a message (the plaintext) into a disguised form (the c

acm_1361677193的专栏 400

zoj 1006 Do the Untwist

Do the Untwist Time Limit: 2 Seconds      Memory Limit: 65536 KB Cryptography deals with methods of secret communication that transform a message (the plaintext) into a disguised form (the cip

小张的专栏 520

Zoj 1006 Do the Untwist

题目来源:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=6 模拟 #include #include #include using namespace std; int main() { char ciphertext[80], plaintext[80]; int ciphercode[100]

Abner 741
上一篇: C语言实验——矩阵转置
下一篇: ZOJ1008 Gnome Tetravex
Lycodeboy
博客等级 码龄11年 1170粉丝 142原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值