#include <string> #include <numeric> #include <algorithm> #include <string_view> class StringComparer { public: static inline auto verifySum(std::string_view w1, std::string_view w2) -> bool { return sumOfCharacters(w1) == sumOfCharacters(w2); } static inline auto sumOfCharacters(std::string_view word) -> int { return std::accumulate(std::begin(word), std::end(word), 0, [](int sum, const char ch) { return sum + static_cast<int>(ch); }); } };
- #include <string>
- #include <numeric>
- #include <algorithm>
- #include <string_view>
- class StringComparer {
- public:
static bool verifySum(const std::string& w1, const std::string& w2) {int sumW1 = sumOfCharacters(w1);int sumW2 = sumOfCharacters(w2);return sumW1 == sumW2;- static inline auto verifySum(std::string_view w1, std::string_view w2) -> bool {
- return sumOfCharacters(w1) == sumOfCharacters(w2);
- }
static int sumOfCharacters(const std::string& word) {return std::accumulate(word.begin(), word.end(), 0, [](int sum, char ch) {- static inline auto sumOfCharacters(std::string_view word) -> int {
- return std::accumulate(std::begin(word), std::end(word), 0, [](int sum, const char ch) {
- return sum + static_cast<int>(ch);
- });
- }
- };