Programming contests

ACM ICPC Central European Regional Contest, Prague, 2007, 2011, Practice Session

November 29, 2011 6:45 PM – February 1, 2012 12:00 AM

Hamming Distance

Have you ever heard of the Hamming distance. It is the number of positions for which the corresponding digits differ. Your task is to write a program that computes this distance for two binary strings.

Input Specification

The input contains several test cases. Each test case consists of two lines. Each line contains one binary number. Any two numbers given in one test case have the same length, which is at most 100 binary digits. The last test case is followed by a line containing the uppercase letter "X".

Output Specification

Your program must output a single line for each test case. The line should contain the statement "Hamming distance is X.", where X is the number of positions where the two numbers have different digits.

Sample Input

  1. 0
  2. 1
  3. 000
  4. 000
  5. 1111111100000000
  6. 0000000011111111
  7. 101
  8. 000
  9. X
download as text file

Output for Sample Input

  1. Hamming distance is 1.
  2. Hamming distance is 0.
  3. Hamming distance is 16.
  4. Hamming distance is 2.
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019