Created
January 29, 2013 14:31
-
-
Save yasuharu519/4664652 to your computer and use it in GitHub Desktop.
QualificationRound No.1 Beautiful strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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