Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create day3-hamming-distance-mayank-17 #120

Merged
merged 2 commits into from
Jan 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Day3/C++/day3-hamming-distance-mayank-17
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @author mayank-17
* @date 03/01/2018
*/

#include <iostream>

using namespace std;

int hammingDistance(string a, string b) {
if(a.length() != b.length()) {
cout << "Strings do not have equal lengths\n";
return -1;
} else {
int count = 0;
for(int i = 0; i < a.length(); i++) {
if(a[i] != b[i]) {
count++;
}
}
return count;
}
}

int main(){
string s1, s2;
cout << "Enter string 1:\n";
cin >> s1;
cout << "Enter string 2:\n";
cin >> s2;
int ans = hammingDistance(s1, s2);
if(ans != 0) {
if(ans > 0) {
cout << "The hamming distance is : " << ans << "\n";
}
} else {
cout << "The hamming distance is : " << ans << "\n";
}
return 0;
}