forked from CodeToExpress/dailycodebase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhamming.cpp
More file actions
26 lines (23 loc) · 689 Bytes
/
hamming.cpp
File metadata and controls
26 lines (23 loc) · 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<iostream>
using namespace std;
int hammingDistance(string first_word, string second_word) {
int count = 0;
if (first_word.size() != second_word.size()) {
return -1;
}
for (int i = 0; i < first_word.size(); i++) {
if (first_word[i] != second_word[i]) {
count++;
}
}
return count;
}
int main() {
string first_word, second_word;
cout << "Enter the first word: ";
cin >> first_word;
cout << "Enter the second word: ";
cin >> second_word;
cout << "The hamming distance between " << first_word << " and " << second_word << " is: " << hammingDistance(first_word, second_word) << endl;
return 0;
}