Do the Untwish

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1006

题意:给定密文按公式解密

注意点:pcode = (ccode + i)%28;的使用

贴代码:

 1 //Problem Name: Do the Untwish
2 //Source: ZOJ 1006
3 //Author: jinjin18
4 //Main idea: easy to solve
5 //Language: C++
6 //======================================================================
7 #include<stdio.h>
8 #include<string.h>
9 #include<map>
10 using namespace std;
11
12 map<char,int> mp;
13
14
15 void init(){
16 mp['_'] = 0;
17 mp['.'] = 27;
18 for(int i = 97; i < 97+26; i++){
19 mp[i] = i - 96;
20 }
21 return;
22 }
23
24 char Findchar(int v){
25 if(v==0){
26 return '_';
27 }
28 if(v==27){
29 return '.';
30 }
31 if(v<27&&v>0){
32 return v + 96;
33 }
34 return '\0';
35 }
36 int main(){
37
38 init();
39 int k;
40 char ptext[100];
41 char ctext[100];
42 while(scanf("%d",&k)!=EOF && k !=0 ){
43 scanf("%s",ctext);
44 int n = strlen(ctext);
45 ptext[n] = '\0';
46 for(int i = 0; i < n; i++){
47 int ccode = mp[ctext[i]];
48 //printf("%d ",ccode);
49 //int pcode = ccode < 28-i? ccode+i:ccode - 28 + i;
50 int pcode = (ccode + i)%28; //写成上面那行i超过28时会出错
51 //printf("%d\n",pcode);
52 ptext[(k*i)%n] = Findchar(pcode);
53
54
55 }
56 printf("%s\n",ptext);
57 }
58 return 0;
59
60 }

ZOJ 1006 Do the Untwish的更多相关文章

  1. [ZOJ 1006] Do the Untwist (模拟实现解密)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=6 题目大意:给你加密方式,请你求出解密. 直接逆运算搞,用到同余定理 ...

  2. ZOJ 1006:Do the Untwist(模拟)

    Do the Untwist Time Limit: 2 Seconds      Memory Limit: 65536 KB Cryptography deals with methods of ...

  3. ●BZOJ 1006 [HNOI2008]神奇的国度(弦图最小染色数)○ZOJ 1015 Fishing Net

    ●赘述题目 给出一张弦图,求其最小染色数. ●题解 网上的唯一“文献”:<弦图与区间图>(cdq),可以学习学习.(有的看不懂) 摘录几个解决改题所需的知识点: ●子图和诱导子图(一定要弄 ...

  4. 题目1006:ZOJ问题(递推规律)

    题目链接:http://ac.jobdu.com/problem.php?pid=1006 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...

  5. 九度OJ 1006 ZOJ问题 (这题測试数据有问题)

    题目1006:ZOJ问题 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:15725 解决:2647 题目描写叙述: 对给定的字符串(仅仅包括'z','o','j'三种字符),推断他能否AC ...

  6. 九度oj 1006 ZOJ问题 2010年浙江大学计算机及软件工程研究生机试真题

    题目1006:ZOJ问题 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:16244 解决:2742 题目描述: 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC.是 ...

  7. 九度OJ 1006:ZOJ问题 (递归)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:18621 解决:3197 题目描述: 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC. 是否AC的规则如下: 1. ...

  8. ZOJ Problem Set - 1006 Do the Untwist

    今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...

  9. 题目1006:ZOJ问题

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:13212 解决:2214 题目描述: 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC. 是否AC的规则如下:1. ...

随机推荐

  1. Mice and Rice(queue的用法)

    Mice and Rice(queue的用法) Mice and Rice is the name of a programming contest in which each programmer ...

  2. Java知识系统回顾整理01基础06数组05复制数组

    数组的长度是不可变的,一旦分配好空间,是多长,就多长,不能增加也不能减少 一.复制数组 把一个数组的值,复制到另一个数组中 System.arraycopy(src, srcPos, dest, de ...

  3. arduino中SCoop库的简单应用案例

    转载:https://www.csdn.net/gather_27/MtTaggzsMDExMS1ibG9n.html arduino中SCoop库的简单应用案例首先这篇文章来在视频https://v ...

  4. Centos下Oracle11gR2安装教程与自动化配置脚本

    系统环境准备 开发组件与依赖库安装 安装centos时选择Server with GUI,右面的可以不勾选,后面统一来装 配置本地yum源 以上包如果缺乏可配置本地yum源进行安装 sudo moun ...

  5. Python 导入模块的两种方法:import xxx 和from...import xxx

    import 方式导入模块 import tool.getsum.add # 导入模块,优先会从启动文件的当前目录开始寻找 # 如果找到,就使用 # 如果找不到,会在系统模块存放目录去 tool.ge ...

  6. springCloud微服务调用失败【CannotGetJdbcConnectionException: Failed to obtain JDBC Connection】

    详情如下: 2019-07-28 10:56:18.229 ERROR 16212 --- [nio-8081-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet ...

  7. Python数据类型--元组(tuple)

    元组与列表非常相似,最大区别在于: (1)元组是不可修改的,定义之后就"固定"了. (2)元组在形式上是用()这样的圆括号括起来 (3)元组不能插入或删除元素 注:元素可修改与不可 ...

  8. T-sql语句,group by 加 order by的使用方法

    select AuHousesID,sum(Turnover) from Auction group by AuHousesID order by sum(Turnover) desc

  9. HTML <del> 标签

    HTML <del> 标签 什么是<del> 标签? 定义文档中已被删除的文本. 实例 a month  is <del>25</del> 30 day ...

  10. Spring Aop 详解二

    这是Spring Aop的第二篇,案例代码很详解,可以查看https://gitee.com/haimama/java-study/tree/master/spring-aop-demo. 阅读前,建 ...