HUST 1404 Hamming Distance (String)

Source: Internet
Author: User
Tags define local

Hamming Distance

Description

There are 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, computes this distance for the binary strings.

Input

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

Output

Your program must, output A, single, line, test case. The line should contain the statement "Hamming distance are X.", where X is the number of positions where the N Umbers has different digits.

Sample Input

0100000011111111000000000000000011111111101000X

Sample Output

Hamming distance is 1.Hamming distance is 0.Hamming distance are 16.Hamming distance is 2.

Puzzle: Read two strings of the same length, from the first bit backwards, if not the same, ans++. X end.

#include <cstdio>#include<iostream>#include<string>#include<sstream>#include<cstring>#include<stack>#include<queue>#include<algorithm>#include<cmath>#include<map>#definePI ACOs (-1.0)#defineMS (a) memset (A,0,sizeof (a))#defineMSP Memset (Mp,0,sizeof (MP))#defineMSV memset (vis,0,sizeof (VIS))using namespacestd;//#define LOCALintMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);#endif //LOCALIos::sync_with_stdio (false); Chara[ -],b[ -];  while(cin>>a&&a[0]!='X') {cin>>b; intans=0;  for(intI=0, S=strlen (a); i<s;i++)        {            if(A[i]!=b[i]) ans++; } printf ("Hamming distance is%d.\n", ans); }    return 0;}
View Code

HUST 1404 Hamming Distance (String)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.