Do the Untwist
Do the Untwist
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 982 Accepted Submission(s): 638
Problem Description
| Array | 0 | 1 | 2 |
| plaintext | 'c' | 'a' | 't' |
| plaincode | 3 | 1 | 20 |
| ciphercode | 3 | 19 | 27 |
| ciphertext | 'c' | 's' | '.' |
Sample Input
5 cs.
101 thqqxw.lui.qswer
3 b_ylxmhzjsys.virpbkr
0
Sample Output
cat
this_is_a_secret
beware._dogs_barking 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1129 题目意思很简单,倒推明文;题目给出的例子是:【cat --> cs.】
第一步:把cat转化成对应数字 plaincode,文中有提到,_=0, .=27, a=1 ...【cat --> 3,1,20】
第二步:利用公式将 plaincode转化成密文对应的数字 ciphercode【3,1,20 --> 3,19,27】
第三步:将 ciphercode转化成密文 【3,19,27 --> cs.】
题目给出密匙k和密文,要求求出明文; 此题最关键的是公式的转化!
公式如下:
明文-->密文:ciphercode[i] = (plaincode[ki mod n] - i) mod 28.
密文-->明文:plaincode[ki mod n] = (ciphercode[i] + i) mod 28.![]()
#include<stdio.h>
#include<string.h>
int main()
{
char s[],b[];
int i,j,n,k;
while(scanf("%d",&k),k)
{
scanf("%s",s);
n=strlen(s);
for(i=;i<n;i++)
{
if(s[i]=='_')
s[i]=;
else if(s[i]=='.')
s[i]=;
else
s[i]=s[i]-'a'+;
}
for(i=;i<n;i++)
{
b[k*i%n]=(s[i]+i)%;
}
for(i=;i<n;i++)
{
if(b[i]==)
printf(".");
else if(b[i]==)
printf("_");
else
printf("%c",b[i]+'a'-);
}
printf("\n");
}
return ;
}
Do the Untwist的更多相关文章
- 1006 Do the Untwist
考察编程基础知识,用到字符和数字相互转化等.形式是描述清楚明文和暗文的转化规则. #include <stdio.h> #include <string.h> #define ...
- ZOJ 1006:Do the Untwist(模拟)
Do the Untwist Time Limit: 2 Seconds Memory Limit: 65536 KB Cryptography deals with methods of ...
- Do the Untwist(模拟)
ZOJ Problem Set - 1006 Do the Untwist Time Limit: 2 Seconds Memory Limit: 65536 KB Cryptography ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
- [ZOJ 1006] Do the Untwist (模拟实现解密)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=6 题目大意:给你加密方式,请你求出解密. 直接逆运算搞,用到同余定理 ...
- ACM/ICPC ZOJ1006-Do the Untwist 解题代码
#include <iostream> #include <string> #include <stdlib.h> using namespace std; int ...
- ZOJ1006 Do the Untwist
简单模拟~ #include<bits/stdc++.h> using namespace std; ; int a[maxn]; unordered_map<char,int> ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
随机推荐
- 【KMP】【字符串】KMP字符串匹配算法 学习笔记
一.简介 KMP是由Knuth.Morris和Prat发明的字符串匹配算法,它的时间复杂度是均摊\(O(n+m)\).其实用Hash也可以做到线性,只不过Hash存在极其微小的难以避免的冲突. ...
- AMD、CMD/AMD与CMD的区别
http://blog.csdn.net/jackwen110200/article/details/52105493
- 关于es6 import export的学习随笔
记得之前的一次面试中,有个面试官问了我关于es6导入和导出的一些知识点,可惜当时对这方面没在意,只知道每次机械的import和export,也不知道为啥要这样用,现在静下心来,好好的把这块看了下,顺便 ...
- os.path模块
什么是os.path模块 该模块用于处理路径,我们知道python是一门跨平台的语言,二每种操作系统,文件路径是截然不同的,为了使程序可以在不同平台生正确运行,python提供了该模块,使用该模块可以 ...
- Q205 同构字符串
给定两个字符串 s 和 t,判断它们是否是同构的. 如果 s 中的字符可以被替换得到 t ,那么这两个字符串是同构的. 所有出现的字符都必须用另一个字符替换,同时保留字符的顺序.两个字符不能映射到同一 ...
- linux运维之top命令
统计信息区前五行是系统整体的统计信息: 第一行是任务队列信息,同 uptime 命令的执行结果.其内容如下: 01:06:48 当前时间 up 1:22 系统运行时间,格式为时:分 1 user 当 ...
- Ace教你一步一步做Android新闻客户端(四) 优化Bitmap大法
我计划着把需要用到的知识分解开来写,趁着我们要开发这款客户端的机会把安卓所有移动客户端开发中的技术贯穿其中,也是我自己成长的过程.By Ace in 20160121 我们开发一款新闻客户端程序,它的 ...
- C++11并发编程:async,future,packaged_task,promise
一:async std::async:用于创建异步任务,可以代替创建线程,函数原型:async(std::launch::async | std::launch::deferred, f, args. ...
- 修改OPENSUSE 桌面快速搜索快捷键
- PHP中break及continue两个流程控制指令解析
<?php $arr = array( 'a' => '0a0', 'b' => '0b0', 'c' => '0c0', 'd' => '0d0', 'e' => ...