Advertisement
Razali

Word Score

Nov 14th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. /*
  2.  * <summary> Compute the score of a word based on its letters </summary>
  3.  * <param = "word"> A string from which to compute the score </param>
  4.  * <return> The total score for the word </return>
  5.  * <precond> "word" should be a null terminated string </precond>
  6.  */
  7. int compute_score(char * word)
  8. {
  9.     int length = strlen(word);
  10.     int i, score = 0;
  11.    
  12.     for(i = 0; i < length; i++)
  13.     {
  14.         switch(word[i])
  15.         {
  16.             case 'Q' : case 'Z' :
  17.                 score += 10;
  18.                 break;
  19.                
  20.             case 'J' : case 'X' :
  21.                 score += 8;
  22.                 break;
  23.                
  24.             case 'K' :
  25.                 score += 5;
  26.                 break;
  27.                
  28.             case 'F' : case 'H' : case 'V' : case 'W' : case 'Y' :
  29.                 score += 4;
  30.                 break;
  31.                
  32.             case 'B' : case 'C' : case 'M' : case 'P' :
  33.                 score += 3;
  34.                 break;
  35.                
  36.             case 'D' : case 'G' :
  37.                 score += 2;
  38.                 break;
  39.                
  40.             default :
  41.                 score += 1;
  42.         }
  43.     }  
  44.    
  45.     return score;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement