HUST 1404 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(字符串)的更多相关文章
- 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 ...
- 64. 海明距离(Hamming Distance)
[本文链接] http://www.cnblogs.com/hellogiser/p/hamming-distance.html [介绍] 在信息领域,两个长度相等的字符串的海明距离是在相同位置上不同 ...
- 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 ...
- HDU 4712:Hamming Distance
Hamming Distance Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
- 海明距离hamming distance
仔细阅读ORB的代码,发现有很多细节不是很明白,其中就有用暴力方式测试Keypoints的距离,用的是HammingLUT,上网查了才知道,hamming距离是相差位数.这样就好理解了. 我理解的Ha ...
- hdu 4712 Hamming Distance(随机函数暴力)
http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...
- HDU 472 Hamming Distance (随机数)
Hamming Distance Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) To ...
- 461. Hamming Distance(leetcode)
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- Codeforces 608B. Hamming Distance Sum 模拟
B. Hamming Distance Sum time limit per test: 2 seconds memory limit per test:256 megabytes input: st ...
随机推荐
- Arch安装KDE5
plasma desktop Install the plasma-meta meta-package or the plasma group. Alternatively, for a more m ...
- canvas画扇形图(本文来自于http://jo2.org/html5-canvas-sector/)
1.定义画扇形的构造函数: //扇形CanvasRenderingContext2D.prototype.sector = function (x, y, radius, sDeg, eDeg) {/ ...
- trove instance service 总结
def create(self, req, body, tenant_id): # TODO(hub-cap): turn this into middleware LOG.info(_LI(&quo ...
- html-----vedio标签(HTML5新标签VIDEO在IOS上默认全屏播放)
今天做一个app时发现一个问题,应用html5中的video标签加载视频,在Android手机上默认播放大小,但是换成iPhone手机上出问题了,默认弹出全屏播放,查找了好多论坛,都没有谈论这个的.然 ...
- [SQL基础教程] 2-1 SELECT语句基础
[SQL基础教程] 2-1 SELECT语句基础 列的查询 Syntax SELECT<列名>,..... FROM<表名>; SELECT col_1, col_2 FROM ...
- [Q]图框识别问题
一个CAD文件可能包含很多张(页)图,每张图通常包含在一个图框里,这个图框通常是矩形的. 打图精灵识别图框所在区域,然后打印该区域,打图精灵识别图框实际上是识别最外侧的矩形(无矩形打印见下文) 如A矩 ...
- 朗姆达表达式类似IN查询条件
if (list.Contains("全部")) { model.All = true; } ...
- 对web.config加密,和解密码详细说明
可以使用受保护配置来加密 Web 应用程序配置文件(如 Web.config 文件)中的敏感信息(包括用户名和密码.数据库连接字符串和加密密钥).对配置信息进行加密后,即使攻击者获取了对配置文件的访问 ...
- intellig idea 快捷键
可以在设置中更改为 eclipse 风格的快捷键. 默认 按住 ctlr + 左键,会调整到对应的声明处, 如果有实现类,eclipse中给予了选择. 在idea 中如果想直接调整到实现类,那么采用快 ...
- .net 可枚举类型的构建方法
数组可以使用foreach遍历数组,其实只要实现GetEnumertor方法的类型都可以使用foreach结构遍历数组. 首先看下代码: //笔类 public class Pencil { publ ...