#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, char ch) { return sum + ch; }); } };
- #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);- return std::accumulate(std::begin(word), std::end(word), 0, [](int sum, char ch) {
- return sum + ch;
- });
- }
- };