<swustoj>?id=56 Hamming Distance

链接http://acm.swust.edu.cn/problem/56/

汉明距离http://baike.baidu.com/view/725269.htm

#include <stdio.h>
#include <string.h>
int main()
{
    int i,count;
    char str_1[105];
    char str_2[105];
    while(scanf("%s",str_1)&&str_1[0]!=‘X‘)
    {
        count=0;
        scanf("%s",str_2);
        for(i=0;i<strlen(str_1);i++)
        {
            if(str_1[i]!=str_2[i])
            {
                count++;
            }
        }
        printf("Hamming distance is %d.\n",count);
    }
    return 0;
}
时间: 2024-10-09 11:14:10

<swustoj>?id=56 Hamming Distance的相关文章

461. Hamming Distance

The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calculate the Hamming distance. Note:0 ≤ x, y < 2^31. Example: Input: x = 1, y = 4 Output: 2 Explanation:

HDU 4712 Hamming Distance (随机函数)

Hamming Distance Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1806    Accepted Submission(s): 714 Problem Description (From wikipedia) For binary strings a and b the Hamming distance is equal

UVa 729 - The Hamming Distance Problem

题目:构造n位01串,其中有m个1的所有组合. 分析:搜索.枚举.可以利用库函数,求解,也可以利用dfs求解:我这里采用位运算计算组合数. 说明:注意库啊! #include <iostream> #include <cstdlib> #include <cstdio> using namespace std; int S[20]; int main() { int T,N,M; while ( cin >> T ) for ( int t = 1 ; t

461. Hamming Distance(leetcode)

The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calculate the Hamming distance. Note:0 ≤ x, y < 2^31. Example: Input: x = 1, y = 4 Output: 2 Explanation:

461. Hamming Distance【数学|位运算】

2017/3/14 15:23:55 The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calculate the Hamming distance. 题目要求:求两个数字二进制位中同一位置不同bit的个数. 解法1  Java    利用1的移位依次匹配是否对

相似算法 ,Java实例9 - 汉明距离 Hamming Distance

Java实例9 - 汉明距离 Hamming Distance http://blog.csdn.net/kindterry/article/details/6581344 /**在信息理论中,两个等长字符串之间的汉明距离 * 是两个字符串对应位置上不同字符的个数, * 换句话说,汉明距离就是将一个字符串替换成另外一个字符串所需要替换的字符长度. *例如,1011101和1001001之间的汉明距离是2, *toned和roses之间的汉明距离是3. *汉明重量是字符串相对于同样长度的零字符串的

729 - The Hamming Distance Problem

// 题意: // 输入两个整数N, H,按照字典序输出所有长度为N,恰好包含H个1的01串 // 规模:1<=H<=N<=16 // 算法A:2^N枚举,输出1的个数为H的.采用递归枚举 // 从bits[d]开始确定,已经用了c0个0和c1个1 #include<cstdio> #include<cstring> #include<iostream> #include<string> #include<algorithm>

LeetCode解题思路:461. Hamming Distance

The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calculate the Hamming distance. Note:0 ≤ x, y < 231. Example: Input: x = 1, y = 4 Output: 2 Explanation: 1

LeetCode 461. Hamming Distance

The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calculate the Hamming distance. Note:0 ≤ x, y < 231. Example: Input: x = 1, y = 4 Output: 2 Explanation: 1