Hamming Distance

Description

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

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

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

0
1
000
000
1111111100000000
0000000011111111
101
000
X

Sample Output

Hamming distance is 1.
Hamming distance is 0.
Hamming distance is 16.
Hamming distance is 2. 题解:读取两个相同长度字符串,从第一位往后对比,如果不一样,ans++。X结束。
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <cstring>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <map>
#define PI acos(-1.0)
#define ms(a) memset(a,0,sizeof(a))
#define msp memset(mp,0,sizeof(mp))
#define msv memset(vis,0,sizeof(vis))
using namespace std;
//#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif // LOCAL
ios::sync_with_stdio(false);
char a[],b[];
while(cin>>a&&a[]!='X')
{
cin>>b;
int ans=;
for(int i=,s=strlen(a);i<s;i++)
{
if(a[i]!=b[i])ans++;
}
printf("Hamming distance is %d.\n",ans);
}
return ;
}

HUST 1404 Hamming Distance(字符串)的更多相关文章

  1. 461. Hamming Distance and 477. Total Hamming Distance in Python

    题目: The Hamming distance between two integers is the number of positions at which the corresponding ...

  2. 64. 海明距离(Hamming Distance)

    [本文链接] http://www.cnblogs.com/hellogiser/p/hamming-distance.html [介绍] 在信息领域,两个长度相等的字符串的海明距离是在相同位置上不同 ...

  3. hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

  4. HDU 4712:Hamming Distance

    Hamming Distance Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) ...

  5. 海明距离hamming distance

    仔细阅读ORB的代码,发现有很多细节不是很明白,其中就有用暴力方式测试Keypoints的距离,用的是HammingLUT,上网查了才知道,hamming距离是相差位数.这样就好理解了. 我理解的Ha ...

  6. hdu 4712 Hamming Distance(随机函数暴力)

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

  7. HDU 472 Hamming Distance (随机数)

    Hamming Distance Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) To ...

  8. 461. Hamming Distance(leetcode)

    The Hamming distance between two integers is the number of positions at which the corresponding bits ...

  9. Codeforces 608B. Hamming Distance Sum 模拟

    B. Hamming Distance Sum time limit per test: 2 seconds memory limit per test:256 megabytes input: st ...

随机推荐

  1. nyoj 79 拦截导弹 (动态规划)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=79 题意即求最长单调递减子序列 #include<iostream> #inc ...

  2. Java写入文件

    import java.io.File;import java.io.FileNotFoundException;import java.io.PrintWriter; public class Fi ...

  3. 邂逅python

    你很美 幸运遇见你 很幸运,能在现在这么多繁杂的语言中选择python.初识python是在2016年的七月.大二学期刚刚结束,留在学校准备学点东西.刚好听同学说下学期要学习python,所以决定要学 ...

  4. CodeForces 670D Magic Powder

    二分. 二分一下答案,然后验证一下. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cst ...

  5. CodeForces 685B Kay and Snowflake

    树的重心,树形$dp$. 记录以$x$为$root$的子树的节点个数为$sz[x]$,重儿子为$son[x]$,重心为$ans[x]$. 首先要知道一个结论:以$x$为$root$的子树的重心$ans ...

  6. [DP优化方法之斜率DP]

    什么是斜率dp呢 大概就把一些单调的分组问题 从O(N^2)降到O(N) 具体的话我就不多说了 看论文: http://www.cnblogs.com/ka200812/archive/2012/08 ...

  7. android弹出dialog后,activity得到焦点

    1.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,WindowManager.LayoutParams.FLAG ...

  8. PHP短信发送服务 youe短信企业服务

    /** * 通用短信平台HTTP接口POST方式发送短信实例 * 返回字符串 * 一般情况下调用此方法 */ function postSendMessage($msgContents,$phoneL ...

  9. 重新注册.netframework4.0

    IIS和.netfw4.0安装顺序是从前到后,如果不小心颠倒了,无所谓. 打开程序-运行-cmd:输入一下命令重新注册IIS C:\WINDOWS\Microsoft.NET\Framework\v4 ...

  10. iOS开发之视差滚动视图

    首先声明一点,由于自己iOS开发经验有限,这里给下面将要实现的效果起名叫视差滚动视图,自己也不知道是否严谨,等以后有经验了,再来更新吧. 一.需求 有的时候我们可能会有这样一种需求,在一个UITabl ...