space=1&num=1404 ">1404. Easy to hack!
Time limit:1.0 Second
Memory limit:64 MB
When Vito Maretti writes a important letter he encrypts it. His method isn't very reliable but it's enough to make any detective understand nothing Sheriff doesn ' t like the such state of affairs. He wants to hack the cipher of Vito Maretti and he promises to forget on all of the your faults if you do this for him. Detectives would tell you about this cipher looks like. Each of the word is enciphered separately. Assume an example this consists only of the small Latin letters. At first step every letter are replaced with the corresponding number:aWith0,bWith1,CWith2, ...,ZWith -. Then 5 was added to the first number, the first number was added to the second one, the second number–to the third one and So on. After that if some number exceeds it was replaced with the residue of division of this number by 26. And then those numbers is replaced back with the letters. Let ' s encipher the wordSecret.
Step 0. S e c r e tstep 1. 4 2 4 19Step 2. 69Step 3. 1 3 17Step 4. X b d u y r
We ' ve got the word
Xbduyr. Inputyou is given an encrypted word of small Latin letters not longer than. Outputthe original word. Sample
input |
Output |
Xbduyr |
Secret |
problem Author:Vladimir Yakovlev
problem Source:The 12th School pupils Collegiate programming Contest of the Sverdlovsk region (October 15, 2005)
Analysis: Directly according to test instructions simulation can be.
AC Code:
#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] + +; for (int i=1, i<n; i++) {while (A[i] < a[i-1]) a[i] + =; 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;}
Copyright notice: This article sxk original article, reproduced this article, please add the link!!!
URAL 1404. Easy to hack! Simulation