I have advanced to the first round of Google Code Jam 2012 by solving 3/4 questions.
Speaking in Tongues:
Speaking in Tongues:
import sys
if __name__ == '__main__':
f = sys.stdin
if len(sys.argv) >= 2:
fn = sys.argv[1]
if fn != '-':
f = open(fn)
output = open('tongout.out', 'w')
t = int(f.readline())
for test in xrange(1, t+1):
str1 = "Case #%d: " %(test)
output.write(str1)
string = f.readline().strip()
ans = []
for i in string:
if i == 'a':
ans.append('y')
elif i == 'b':
ans.append('h')
elif i == 'c':
ans.append('e')
elif i == 'd':
ans.append('s')
elif i == 'e':
ans.append('o')
elif i == 'f':
ans.append('c')
elif i == 'g':
ans.append('v')
elif i == 'h':
ans.append('x')
elif i == 'i':
ans.append('d')
elif i == 'j':
ans.append('u')
elif i == 'k':
ans.append('i')
elif i == 'l':
ans.append('g')
elif i == 'm':
ans.append('l')
elif i == 'n':
ans.append('b')
elif i == 'o':
ans.append('k')
elif i == 'p':
ans.append('r')
elif i == 'q':
ans.append('z')
elif i == 'r':
ans.append('t')
elif i == 's':
ans.append('n')
elif i == 't':
ans.append('w')
elif i == 'u':
ans.append('j')
elif i == 'v':
ans.append('p')
elif i == 'w':
ans.append('f')
elif i == 'x':
ans.append('m')
elif i == 'y':
ans.append('a')
elif i == 'z':
ans.append('q')
elif i == ' ':
ans.append(' ')
out = ''.join(ans)
output.write(out+"\n")
output.close()
Dancing With the Googlers:import sys
if __name__ == '__main__':
f = sys.stdin
if len(sys.argv) >= 2:
fn = sys.argv[1]
if fn != '-':
f = open(fn)
output = open('danout.out', 'w')
t = int(f.readline())
for test in xrange(1, t+1):
c = 0
str1 = "Case #%d: " %(test)
output.write(str1)
arr = map(int, f.readline().strip().split())
n = arr[0]
s = arr[1]
p = arr[2]
goog = arr[3:]
goog.sort()
fl=0
y = 0
for k in goog:
temp = k-p
temp/=2
if fl==1 and k>=y:
c+=1
elif temp >= p-1 and temp>=0:
c+=1
fl=1
y=k
elif temp >= p-2 and s>=1 and temp>=0:
c+=1
s-=1
output.write(str(c)+"\n")
output.close()
Recycled Numbers:import sys
if __name__ == '__main__':
f = sys.stdin
if len(sys.argv) >= 2:
fn = sys.argv[1]
if fn != '-':
f = open(fn)
output = open('recout1.out', 'w')
t = int(f.readline())
for test in xrange(1, t+1):
str1 = "Case #%d: " %(test)
output.write(str1)
a, b = f.readline().strip().split()
inta = int(a)
intb = int(b)
values = [str(i) for i in range(int(a), int(b)+1)]
c = 0
for i in values:
arr = []
for j in range(len(i), 0, -1):
ans = i[j:]+i[:j]
ans = int(ans)
if ans > int(i) and ans >= inta and ans <= intb and ans not in arr:
arr.append(ans)
c+=1
output.write(str(c)+"\n")
output.close()
No comments:
Post a Comment