fork download
  1. #include <stdio.h>
  2.  
  3. int compute_score_range(char* word, char low)
  4. {
  5. int points[] = {1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1,1, 1, 4, 4, 8, 4, 10};
  6. const int elements = sizeof points / sizeof points[0];
  7.  
  8. int total = 0;
  9. while(*word)
  10. {
  11. if (*word >= low && *word -low < elements)
  12. {
  13. int indeks = *word - low;
  14. total += points[indeks];
  15. }
  16. ++word;
  17. }
  18.  
  19. return total;
  20. }
  21.  
  22. int compute_score(char* word)
  23. {
  24. return compute_score_range(word, 'A') + compute_score_range(word, 'a');
  25. }
  26.  
  27.  
  28. int main(void)
  29. {
  30. // Get input words from both players
  31. char* word1 = "idflfJIO";
  32. char* word2 = "idsfd,,,...74537flfdfJIO";
  33.  
  34. // Score both words
  35. int score1 = compute_score(word1);
  36. int score2 = compute_score(word2);
  37.  
  38. if (score1 > score2)
  39. {
  40. printf("Player 1 wins with score %d!\n", score1);
  41. }
  42. else if (score1 < score2)
  43. {
  44. printf("Player 2 wins with score %d!\n", score2);
  45. }
  46. else
  47. {
  48. printf("Tie!\n");
  49. }
  50. }
  51.  
Success #stdin #stdout 0s 5536KB
stdin
Standard input is empty
stdout
Player 2 wins with score 35!