Skip to content

Commit

Permalink
Add kattis prob progressivescramble in python3
Browse files Browse the repository at this point in the history
  • Loading branch information
iandioch committed Mar 21, 2018
1 parent 4537f2b commit 7a5b5d0
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions kattis/progressivescramble/solution.py
@@ -0,0 +1,49 @@
def encrypt(s):
t = []
for c in s:
a = 0
if c != ' ':
a = ord(c) - ord('a') + 1
if len(t):
t.append(t[-1] + a)
else:
t.append(a)

u = []
for c in t:
c %= 27
if c == 0:
u.append(' ')
else:
u.append(chr(c + ord('a') - 1))
return ''.join(u)

def decrypt(s):
t = []
tmp = 0
for c in s:
a = 0
if c != ' ':
a = ord(c) - ord('a') + 1
a -= tmp
while a < 0:
a += 27
tmp += a
t.append(a)
u = []
for c in t:
if c == 0:
u.append(' ')
else:
u.append(chr(c + ord('a') - 1))
return ''.join(u)

t = int(input())
for _ in range(t):
s = input()
op = s[0]
s = s[2:]
if op == 'e':
print(encrypt(s))
else:
print(decrypt(s))

0 comments on commit 7a5b5d0

Please sign in to comment.