Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Created on Jan 23, 2012
- @author: willemjan
- '''
- import io
- from root.helper import getInputPath
- from pprint import pprint
- live = True
- file = open(getInputPath(live) + '/alphabet_soup.txt', 'r')
- resultFile = open(getInputPath(live) + '/alphabet_soup_out.txt', 'w')
- cntCases = int(file.readline())
- def hasResult(dictionary):
- usedLetters = {}
- # Loop thru letters in testString
- for letter in list("HACKERCUP"):
- # If letter not in string or no longer in dictionary, return false
- if letter not in dictionary or dictionary[letter] <= 0:
- return False
- else:
- # else add letter to usedLetters to make the delta later on
- if letter not in usedLetters:
- usedLetters[letter] = 1
- else:
- usedLetters[letter] += 1
- # Word found, perform delta
- for foundLetter in usedLetters:
- dictionary[foundLetter] -= 1
- return True
- i = 0
- while i < cntCases:
- i+=1
- line = file.readline().strip()
- dictionary = {}
- letters = list(line)
- for x in letters:
- if x not in dictionary:
- dictionary[x] = 0;
- dictionary[x] += 1
- result = 0
- while True:
- if hasResult(dictionary):
- result += 1
- else:
- break
- resultFile.write('Case #' + str(i) + ': ' + str(result) + '\n')
- resultFile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement