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 ...
随机推荐
- python-%操作符
1.打印字符串 print("His name is %s"%("Aviad")) His name is Aviad 2.打印整数print("He ...
- 114th LeetCode Weekly Contest Array of Doubled Pairs
Given an array of integers A with even length, return true if and only if it is possible to reorder ...
- [源代码]List的增加与删除
// Removes the element at the given index. The size of the list is // decreased by one. // public vo ...
- python爬虫之趟雷
python爬虫之趟雷整理 雷一:URLError 问题具体描述:urllib.error.URLError: <urlopen error [Errno 11004] getaddrinfo ...
- 2.3 if switch for等流程控制
if条件中可以写多个语句,语句的作用域仅限于if,不可在if之外的地方使用 package main import ( "fmt" "io/ioutil" ) ...
- C语言中的输入方式
在c语言中,有gets().scanf().getchar()等输入方式,但是不同的方式处理的方式不同. scanf()读取时遇见tab.space.enter时会结束读取,不会舍弃最后的回车符(即回 ...
- c#字典排序
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- RabbitMQ学习整理
1.什么是消息队列? 概念: 消息队列(Message Queue,简称MQ),本质是个队列,FIFO先入先出,只不过队列中存放的内容是一些Message. 2.为什么要用消息队列,应用场景? 不同系 ...
- centos系统为php安装memcached扩展
1. 通过yum安装 yum -y install memcached #安装完成后执行: memcached -h #出现memcached帮助信息说明安装成功 2. 加入启动服务 chkconfi ...
- java使用POI进行 Excel文件解析
package com.timevale.esign.vip.util; import java.io.File; import java.io.FileInputStream; import jav ...