24 lines
479 B
C++
24 lines
479 B
C++
#include "hamming.h"
|
|
|
|
#include <functional>
|
|
#include <numeric>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
|
|
namespace hamming {
|
|
|
|
using namespace std;
|
|
|
|
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>());
|
|
}
|
|
|
|
}
|