问题 J: Progressive Scramble

时间限制: 1 Sec  内存限制: 128 MB

提交: 108  解决: 45

[提交] [状态] [命题人:admin]

题目描述

You are a member of a naive spy agency. For secure communication,members of the agency use a very simple encryption algorithm – which changes each symbol in the message ‘progressively’, i.e., based on the symbols preceding it. The allowed symbols are space and the 26 lowercase English letters. For encryption purposes we assign them the values 0 (for space) and 1 through 26 (for a–z). We’ll let v(s) represent the numeric value of symbol s.

Consider a message with symbols s1, s2, . . . , sn. The encryption algorithm starts by converting the first symbol s1 into its associated value u1 = v(s1). Then for each subsequent symbol si in the message, the computed value is ui = v(si) + ui−1 — the sum of its associated value and the computed value for the previous symbol. (Note that when there is a space in the input

message, the previous scrambled letter is repeated.) This process continues until all the ui are computed.

At this point, the message is a sequence of numeric values. We need to convert it back to symbols to print it out. We do this by taking the value ui modulo 27 (since there are 27 valid symbols), and replacing that value with its corresponding symbol. For example, if ui = 32, then 32 mod 27 = 5, which is the symbol ‘e’ (since v(e) = 5).

Let’s look at an example. Suppose we want to encrypt the string “my pie”. 

1. First, convert each symbol si into v(si): [13, 25, 0, 16, 9, 5].

2. Next, compute each ui: [13, 38, 38, 54, 63, 68].

3. Then, use modulus on the ui: [13, 11, 11, 0, 9, 14].

4. Finally, convert these back to symbols: “mkk in”.

Create a program that takes text and encrypts it using this algorithm, and also decrypts text that has been encrypted with this algorithm.

输入

The input to your program consists of a single integer 1 ≤ n ≤ 100 on its own line. This number is followed by n lines, each containing the letter ‘e’ or ‘d’, a single space, and then a message made up of lowercase letters (a–z) and spaces, continuing to the end of the line. Each message is between 1 and 80 characters long. The letters ‘d’ and ‘e’ indicate that your program decrypts or encrypts the subsequent string, respectively.

输出

Output the result of encrypting or decrypting each message from the input on its own separate line. Note that differences in whitespace are significant in this problem. Therefore your output must match the correct output character-for-character, including spaces.

样例输入

7
e testing multiple letters rrrrrrrrrrrrr
e this particularly long  sentence can test encryption
d tajbbrsjcloiuvmywwhwjqqqinauzmpuuxyllejbvv nqhfvoxlz
e my pie
d mkk in
e the quick brown fox jumps over the lazy dog
d taffwqzbmmofuqddjyvvezlatthchzzs eeqrqoosgn

样例输出

tyqjsfmmzteygwhmmycwpulddvmdvmdvmdvmdv
tajbbrsjcloiuvmywwhwjqqqinauzmpuuxyllejbvv nqhfvoxlz
this particularly long  sentence can test encryption
mkk in
my pie
taffwqzbmmofuqddjyvvezlatthchzzs eeqrqoosgn
the quick brown fox jumps over the lazy dog

很水的一个模拟阿,但比赛时候一直狂怼格式错误,然后瞎改改成WA? 赛后zn说漏掉了字符串第一个就是空格的情况=。=

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rep(i,a,n) for(int i=a;i<n;++i)
#define readc(x) scanf("%c",&x)
#define read(x) scanf("%d",&x)
#define sca(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define read3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define print(x) printf("%d\n",x)
#define mst(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x&-x
#define lson(x) x<<1
#define rson(x) x<<1|1
#define pb push_back
#define mp make_pair
typedef pair<int,int> P;
typedef long long ll;
const int INF =0x3f3f3f3f;
const int inf =0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 105;
const int maxn = 10010;

int n, t;
int ans[maxn];
string s;
int main()
{
  read(t);
  getchar();
  while(t--){
    getline(cin,s);
    ans[2] = s[2] == ' ' ? 0 : s[2] - 'a' + 1;
    if(s[0] == 'e'){
      for(int i = 3; i < s.length(); i++){
        int x = s[i] == ' ' ? 0 : s[i] -'a' + 1;
        ans[i] = ans[i - 1] + x;
      }
      for(int i = 2; i < s.length(); i++){
        printf("%c",ans[i] % 27 ? ans[i] % 27 - 1 + 'a' : ' ');
      }
      printf("\n");
    }
    else{
      int sum = ans[2];
      for(int i = 3; i < s.length(); i++){
        int x = s[i] == ' ' ? 0 : s[i] -'a' + 1;
        while(x < sum)
          x += 27;
        ans[i] = x - sum;
        sum += ans[i];
      }
      for(int i = 2; i < s.length(); i++){
        printf("%c",ans[i] % 27 ? ans[i] % 27 - 1 + 'a' : ' ');
      }
      printf("\n");
    }
  }
  return 0;
}

Progressive Scramble【模拟】的更多相关文章

  1. upc组队赛6 Progressive Scramble【模拟】

    Progressive Scramble 题目描述 You are a member of a naive spy agency. For secure communication,members o ...

  2. Schlumberger Petrel 2016.3 地震解释 油藏模拟

    Schlumberger Petrel 2016.3 地震解释 油藏模拟世界上顶尖的三维地质建模软件,软件为用户提供的工具可以用于地震解释.地质建模.油藏数 值模拟等方面的使用,清晰的地质模型可以描述 ...

  3. (转)PWA(Progressive Web App)渐进式Web应用程序

    PWA 编辑 讨论 PWA(Progressive Web App)是一种理念,使用多种技术来增强web app的功能,可以让网站的体验变得更好,能够模拟一些原生功能,比如通知推送.在移动端利用标准化 ...

  4. PMP模拟考试-2

    1. Increasing resources on the critical path activities may not always shorten the length of the pro ...

  5. PWA(Progressive Web App)入门系列:(一)PWA简单介绍

    前言 PWA做为一门Google推出的WEB端的新技术,长处不言而喻.但眼下对于相关方面的知识不是非常丰富.这里我推出一下这方面的新手教程系列.提供PWA方面学习. 什么是PWA PWA全称Progr ...

  6. 第一个progressive web application,发车!

    progressive web application是谷歌推出的一种渐进式web应用,通过利用service-worker等来达到类似于原生应用,而且在chrome浏览器还可以添加到主页,完全就和一 ...

  7. App开发:模拟服务器数据接口 - MockApi

    为了方便app开发过程中,不受服务器接口的限制,便于客户端功能的快速测试,可以在客户端实现一个模拟服务器数据接口的MockApi模块.本篇文章就尝试为使用gradle的android项目设计实现Moc ...

  8. 故障重现, JAVA进程内存不够时突然挂掉模拟

    背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...

  9. Python 爬虫模拟登陆知乎

    在之前写过一篇使用python爬虫爬取电影天堂资源的博客,重点是如何解析页面和提高爬虫的效率.由于电影天堂上的资源获取权限是所有人都一样的,所以不需要进行登录验证操作,写完那篇文章后又花了些时间研究了 ...

随机推荐

  1. gym101808 E

    提问:我是什么品种的傻逼? 哇看到积水兴高采烈啊.然后就走上了一条不归路. 为什么不归呢,因为我这个法子就是不对的,我总是在想很多很多点围成的一块区域,然后求这一块区域的面积. 然后尝试了各种扫描方法 ...

  2. Oracle管理常用查询语句

    1.查看表空间的名称及大小 select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_sizefrom dba_tablespaces ...

  3. Strassen 矩阵相乘算法(转)

    偶尔在算法课本上面看到矩阵相乘的算法,联想到自己曾经在蓝桥杯系统上曾经做过一道矩阵相乘的题目,当时用的是普通的矩阵相乘的方法,效率极低,勉强通过编译.所以决定研究一下Strassen矩阵相乘算法,由于 ...

  4. Oracle 修改表 Alter Table...

    --增加列ALTER TABLE Student add sex number(2);--删除列ALTER TABLE Student drop column sex;--更改列属性 ALTER TA ...

  5. 谷歌浏览器(Chrome)禁止浏览器缓存 设置

    在开发项目期间用谷歌浏览器调试,他总是缓存我的css样式这个很气人啊,后经过摸索找到了方法,如下 先F12或者shift+ctrl+j 打开调试者工具,在找Network这个tab按钮,点击进入,勾选 ...

  6. 求最短路的三种方法:dijkstra,spfa,floyd

    dijkstra是一种单源最短路算法.在没有负权值的图上,vi..vj..vk是vi到vk最短路的话,一定要走vi到vj的最短路.所以每次取出到起点距离最小的点,从该点出发更新邻接的点的距离,如果更新 ...

  7. 2018-2019-2 20165330《网络对抗技术》Exp5 MSF基础应用

    目录 基础问题 相关知识 实验目的 实验内容 实验步骤 离实战还缺些什么技术或步骤? 实验总结与体会 实验目的 本实践目标是掌握metasploit的基本应用方式,重点常用的三种攻击方式的思路 返回目 ...

  8. AE实现拖拽

    http://edndoc.esri.com/arcobjects/9.2/net/63391c82-c2e6-4797-b2e6-2c1d92f56f44.htm http://help.arcgi ...

  9. Recurrent NN vs Recursive NN

    https://www.bilibili.com/video/av9770302/?p=8 李宏毅深度学习 图很清楚的反映出两者的不同 Recurrent可以看成Recursive的特殊形式,即以特定 ...

  10. python摸爬滚打之day16----类的成员

    1.变量(字段) 实例变量(普通字段): 实例变量封装在对象中, 用的时候直接用对象来调用. 类变量(静态字段): 类变量封装在类中的, 同一个类不同对象都可以用, 用的时候直接用类名调用(对象也能调 ...