Skip to content

Instantly share code, notes, and snippets.

@mugenen
Created April 15, 2012 09:52
Show Gist options
  • Save mugenen/2391608 to your computer and use it in GitHub Desktop.
Save mugenen/2391608 to your computer and use it in GitHub Desktop.
Google Code Jam 2012 Qualification C
import sys
def count(MIN, MAX):
s = set()
L = len(str(MAX))
for i in xrange(MIN, MAX + 1):
for j in xrange(1, L):
div = 10**j
h = i / div
l = i % div
n = l * 10 ** (L - j) + h
if i != n and i < n and n <= MAX and (l * 10 / div) != 0:
s.add((i, n))
return len(s)
N = sys.stdin.readline()
i = 0
for l in sys.stdin:
i += 1
min, max = l.split()
print "Case #{0}: {1}".format(i, count(int(min), int(max)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment