URAL 1404. Easy to Hack! (模拟)

space=1&num=1404">1404. Easy to Hack!

Time limit: 1.0 second

Memory limit: 64 MB

When Vito Maretti writes an important letter he encrypts it. His method is not very reliable but it’s enough to make any detective understand nothing in that letter. Sheriff doesn’t like such state of affairs. He wants to hack
the cipher of Vito Maretti and he promises to forget about all of your faults if you do that for him. Detectives will tell you what this cipher looks like.

Each word is enciphered separately. Assume an example that consists only of the small Latin letters.

At first step every letter is replaced with the corresponding number:
a with 0, b with 1,
c with 2, ..., z with
25
.Then 5 is added to the first number, the first number is added to the second one, the second number – to the third one and so on. After that if some number exceeds 25 it is replaced with the residue of division of this number by 26. And then those
numbers are replaced back with the letters.

Let’s encipher the word secret.

Step 0.   s   e   c   r   e   t
Step 1.   18  4   2   17  4   19
Step 2.   23  27  29  46  50  69
Step 3.   23  1   3   20  24  17
Step 4.   x   b   d   u   y   r

We’ve got the word xbduyr.

Input

You are given an encrypted word of small Latin letters not longer than 100 characters.

Output

the original word.

Sample

input output
xbduyr
secret

Problem Author: Vladimir Yakovlev

Problem Source: The 12th High School Pupils Collegiate Programming Contest of the Sverdlovsk Region (October 15, 2005)

解析:直接按题意模拟就可以。

AC代码:

#include <bits/stdc++.h>
using namespace std;

int a[102];

int main(){
    string s;
    while(cin>>s){
        int n = s.size();
        for(int i=0; i<n; i++) a[i] = s[i] - 'a';
        if(a[0] < 5) a[0] += 26;
        for(int i=1; i<n; i++){
            while(a[i] < a[i-1]) a[i] += 26;
        }
        for(int i=n-1; i>0; i--) a[i] -= a[i-1];
        a[0] -= 5;
        for(int i=0; i<n; i++) printf("%c", a[i] + 'a');
        puts("");
    }
    return 0;
}

版权声明:本文sxk原创文章,转载本文,请添加链接!!!

时间: 2024-10-01 05:14:43

URAL 1404. Easy to Hack! (模拟)的相关文章

Timus 1404. Easy to Hack! 有一个密码问题

When Vito Maretti writes an important letter he encrypts it. His method is not very reliable but it's enough to make any detective understand nothing in that letter. Sheriff doesn't like such state of affairs. He wants to hack the cipher of Vito Mare

URAL 1712. Cipher Grille (模拟)

1712. Cipher Grille Time limit: 0.5 second Memory limit: 64 MB Our program committee uses different tools for problem development: a mailing list, a version control system, an administration system of the Timus Online Judge website, and many others.

zoj 3867 Earthstone: Easy Version(模拟)

#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<stdlib.h> #include<queue> #include<stack> #include<vector> #include<algorithm> #define LL long long using namespace std; c

URAL 1290. Sabotage(STL &amp; 模拟啊)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1290 1290. Sabotage Time limit: 1.0 second Memory limit: 64 MB It is the seventh year of the terrible harmful Galaxy War... Leo Hao is one of the first defenders of his planet. He is lucky! He has gon

URAL(timus) 1280 Topological Sorting(模拟)

Topological Sorting Time limit: 1.0 secondMemory limit: 64 MB Michael wants to win the world championship in programming and decided to study N subjects (for convenience we will number these subjects from 1 to N). Michael has worked out a study plan

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

HDOJ的题目分类

模拟题, 枚举 1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 12