scrabble_score: iteration 1
This commit is contained in:
parent
bab0920f6d
commit
9c9d3a5380
2 changed files with 46 additions and 0 deletions
34
cpp/scrabble-score/scrabble_score.cpp
Normal file
34
cpp/scrabble-score/scrabble_score.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#include "scrabble_score.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
namespace scrabble_score {
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace {
|
||||
|
||||
const unordered_map<char, int> scores_map = {
|
||||
{'A', 1}, {'E', 1}, {'I', 1}, {'O', 1}, {'U', 1},
|
||||
{'L', 1}, {'N', 1}, {'R', 1}, {'S', 1}, {'T', 1},
|
||||
{'D', 2}, {'G', 2},
|
||||
{'B', 3}, {'C', 3}, {'M', 3}, {'P', 3},
|
||||
{'F', 4}, {'H', 4}, {'V', 4}, {'W', 4}, {'Y', 4},
|
||||
{'K', 5},
|
||||
{'J', 8}, {'X', 8},
|
||||
{'Q', 10}, {'Z', 10}
|
||||
};
|
||||
}
|
||||
|
||||
int score(const string &input)
|
||||
{
|
||||
return accumulate(input.cbegin(), input.cend(), 0,
|
||||
[](int acc, char ch) {
|
||||
|
||||
return acc + scores_map.at(toupper(ch));
|
||||
});
|
||||
};
|
||||
|
||||
}
|
||||
12
cpp/scrabble-score/scrabble_score.h
Normal file
12
cpp/scrabble-score/scrabble_score.h
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#define EXERCISM_RUN_ALL_TESTS
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace scrabble_score {
|
||||
|
||||
int score(const std::string &input);
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue