Skip to content

Instantly share code, notes, and snippets.

@yasuharu519
Created January 29, 2013 14:31
Show Gist options
  • Save yasuharu519/4664652 to your computer and use it in GitHub Desktop.
Save yasuharu519/4664652 to your computer and use it in GitHub Desktop.
QualificationRound No.1 Beautiful strings
import sys
from string import ascii_lowercase
def getCharFrequency(string):
result = dict()
for c in string:
lowerC = c.lower()
if lowerC in ascii_lowercase:
if not result.has_key(lowerC):
result[lowerC] = 1
else:
result[lowerC] += 1
return result
def evaluate(string):
Cdict = getCharFrequency(string)
num = 26
result = 0
for c, count in sorted(Cdict.items(), key=lambda x:x[1],
reverse=True):
result += num * count
num -= 1
return result
m = int(sys.stdin.readline())
for i in xrange(m):
string = sys.stdin.readline().rstrip()
print("Case #{0:d}: {1:d}".format(i+1, evaluate(string)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment