Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * <summary> Compute the score of a word based on its letters </summary>
- * <param = "word"> A string from which to compute the score </param>
- * <return> The total score for the word </return>
- * <precond> "word" should be a null terminated string </precond>
- */
- int compute_score(char * word)
- {
- int length = strlen(word);
- int i, score = 0;
- for(i = 0; i < length; i++)
- {
- switch(word[i])
- {
- case 'Q' : case 'Z' :
- score += 10;
- break;
- case 'J' : case 'X' :
- score += 8;
- break;
- case 'K' :
- score += 5;
- break;
- case 'F' : case 'H' : case 'V' : case 'W' : case 'Y' :
- score += 4;
- break;
- case 'B' : case 'C' : case 'M' : case 'P' :
- score += 3;
- break;
- case 'D' : case 'G' :
- score += 2;
- break;
- default :
- score += 1;
- }
- }
- return score;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement