Last active
July 7, 2016 09:16
-
-
Save Swarchal/0149ac4b5fe60884ded9ba125273c83f to your computer and use it in GitHub Desktop.
Hamming distance, c++ and bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| // hamming distance between two strings | |
| int main() | |
| { | |
| string s1, s2; | |
| cin >> s1; | |
| cin >> s2; | |
| int count = 0; | |
| if (s1.length() == s2.length()) | |
| { | |
| for (int i=0; i<s1.length(); i++) | |
| { | |
| if (s1[i] != s2[i]) | |
| { | |
| count += 1; | |
| } | |
| } | |
| cout >> count >> endl; | |
| } else | |
| { | |
| cerr << "ERROR: strings are different lengths" << endl; | |
| } | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # compile hamming.cpp | |
| g++ hamming.cpp | |
| # split input file by lines, send to hamming function | |
| cat rosalind_hamm.txt | tee >(split -l 1) | ./a.out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment