This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
ProgrammingChallenges/ayb.py

39 lines
700 B
Python
Raw Normal View History

2019-05-16 14:18:43 +00:00
#!/usr/bin/env python3
def ayb(s):
A = [None] * 128
Q = []
c = 1
for i in range(len(s)):
code = ord(s[i])
if A[code] is None:
A[code] = c
if c == 1:
c = 0
elif c == 0:
c = 2
else:
c += 1
Q.append((A[code],i))
if c == 1:
c = 0
if c == 0:
c = 2
num = 0
for tup in Q:
value, position = tup
num += value * (c ** (len(s) - position - 1))
return str(num)
def main():
t = int(input())
for i in range(1, t + 1):
print("Case #" + str(i) + ": " + ayb(input()))
if __name__ == "__main__":
main()