hamming: inner_product version

This commit is contained in:
Dmitry Kokorin 2016-02-25 09:54:27 +03:00
parent ead8d3fbf3
commit 055ae4242f
2 changed files with 18 additions and 2 deletions

View file

@ -1,10 +1,24 @@
#include "hamming.h" #include "hamming.h"
#include <functional>
#include <numeric>
#include <stdexcept>
#include <string>
namespace hamming { namespace hamming {
int compute(const char *first, const char *second) { using namespace std;
return 0; int compute(const char *cstr1, const char *cstr2) {
const string str1(cstr1);
const string str2(cstr2);
if (str1.size() != str2.size())
throw domain_error("Strings have different length");
return inner_product(str1.begin(), str1.end(), str2.begin(), 0,
plus<int>(), not_equal_to<char>());
} }
} }

View file

@ -1,5 +1,7 @@
#pragma once #pragma once
#define EXERCISM_RUN_ALL_TESTS
namespace hamming { namespace hamming {
int compute(const char *first, const char *second); int compute(const char *first, const char *second);