38 lines
700 B
Python
Executable file
38 lines
700 B
Python
Executable file
#!/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()
|