mramine364

Hamming Distance

Aug 26th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int hammingDistance(string s1,string s2)
  7. {
  8.     if( s1.size()!=s2.size() )
  9.         return -1;
  10.     int i,j,c=0;
  11.     for(i=0;i<s1.size();i++)
  12.         if( s1[i]!=s2[i] )
  13.             c++;
  14.     return c;
  15. }
  16. int main()
  17. {
  18.    cout << hammingDistance("1011100", "1001101") << endl;
  19.    
  20.    return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment