Hanyuan has recently been playing a lot of scrabble but is struggling to maximise the points he is getting on each word.
Given a string with some spots filled with letters and the others hyphens, and a list of letters that Hanyuan has access to, write a program scrambled_scrabble.c
to find the maximum score he can achieve.
The program should receive three lines of input:
Output Format
If a word can be formed, print to stdout the value of the word. If a word cannot be formed, print "Cannot be done!"
.
The output from your program should look exactly like this:
$ dcc scrambled_scrabble.c -o scrambled_scrabble
$ ./scrambled_scrabble
6
a-eci-
zyhdcb
69
Explanation
The highest scoring words we can make are “azeciy” or “ayeciz”. Assume we use "azeciy" as our word, then we calculate the score as 1 + 26 + 5 + 3 + 9 + 25 = 69.
$ ./scrambled_scrabble
5
--ap-
ufdcb
Cannot be done!
Explanation
There are 3 spots we need to fill using two vowels and a consonant. There is only one vowel in the letter bank we were given, hence we cannot form a word.
When you think your program is working, you can use CSE autotest to test your solution.
$ 1511 csesoc-autotest scrambled_scrabble
You can view the solution code to this problem here.