mirror of https://github.com/me50/kukemuna.git
This commit is contained in:
commit
bf5664c5b2
|
|
@ -0,0 +1,49 @@
|
||||||
|
#include <cs50.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
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};
|
||||||
|
|
||||||
|
int get_score(string word);
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
// Prompt user(s) for two words
|
||||||
|
string word_1 = get_string("Player 1: ");
|
||||||
|
string word_2 = get_string("Player 2: ");
|
||||||
|
|
||||||
|
// Compute the score of each word
|
||||||
|
int score_1 = get_score(word_1);
|
||||||
|
int score_2 = get_score(word_2);
|
||||||
|
|
||||||
|
// Print the winner
|
||||||
|
if (score_1 > score_2)
|
||||||
|
{
|
||||||
|
printf("Player 1 wins!\n");
|
||||||
|
}
|
||||||
|
else if (score_1 < score_2)
|
||||||
|
{
|
||||||
|
printf("Player 2 wins!\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Tie!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_score(string word)
|
||||||
|
{
|
||||||
|
int score = 0;
|
||||||
|
int length = strlen(word);
|
||||||
|
|
||||||
|
for (int i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
if (isalpha(word[i]))
|
||||||
|
{
|
||||||
|
word[i] = toupper(word[i]) - 65;
|
||||||
|
}
|
||||||
|
score += POINTS[(int) word[i]];
|
||||||
|
}
|
||||||
|
return score;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue