Đề bài
Add the tile values for every letter in a word. Ignore case. There are no board multipliers or wildcard tiles.
Letter values:
A, E, I, O, U, L, N, R, S, T: 1 point each.
D, G: 2 each.
B, C, M, P: 3 each.
F, H, V, W, Y: 4 each.
K: 5. J, X: 8 each. Q, Z: 10 each.
Implement word_tile_score(word).
Input
word: The word to score.
Output
Return the sum of all letter values.
Ràng buộc
0 ≤ word length ≤ 10,000. Only ASCII letters are allowed. Empty input scores 0.
Ví dụ
Đầu vào:
word = "code"
Kết quả mong đợi:
expected = 7
Đầu vào:
std::string word = "code";
Kết quả mong đợi:
long long expected = 7;
Đầu vào:
string word = "code";
Kết quả mong đợi:
long expected = 7;
Giải thích
C is worth 3, O is 1, D is 2, and E is 1: 3 + 1 + 2 + 1 = 7.
Đầu vào:
word = "Quiz"
Kết quả mong đợi:
expected = 22
Đầu vào:
std::string word = "Quiz";
Kết quả mong đợi:
long long expected = 22;
Đầu vào:
string word = "Quiz";
Kết quả mong đợi:
long expected = 22;
Giải thích
Case does not matter. Q + U + I + Z gives 10 + 1 + 1 + 10 = 22.
Tham khảo
Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.