hamming: inner_product version
This commit is contained in:
parent
ead8d3fbf3
commit
055ae4242f
2 changed files with 18 additions and 2 deletions
|
|
@ -1,10 +1,24 @@
|
|||
#include "hamming.h"
|
||||
|
||||
#include <functional>
|
||||
#include <numeric>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
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>());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#define EXERCISM_RUN_ALL_TESTS
|
||||
|
||||
namespace hamming {
|
||||
|
||||
int compute(const char *first, const char *second);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue