美文网首页
2019-01-22-B二进制异或问题

2019-01-22-B二进制异或问题

作者: 尚恩_3295 | 来源:发表于2019-01-22 16:55 被阅读0次

Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.

One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.

In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The i-th digit of the answer is 1 if and only if the i-th digit of the two given numbers differ. In the other case the i-th digit of the answer is 0.

Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.

Now you are going to take part in Shapur's contest. See if you are faster and more accurate.

Input
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.

Output
Write one line — the corresponding answer. Do not omit the leading 0s.

Examples
Input
1010100
0100101
Output
1110001
Input
000
111
Output
111
Input
1110
1010
Output
0100
Input
01110
01100
Output
00010
问题链接:https://cn.vjudge.net/contest/279628#problem/B
问题简述:二进制异或运算
问题分析:
1.首先是输入两个二进制数并且以换行结束
2.在进行两个char数组的各个字符是否相等输出结果

程序说明:刚开始的想法:
1.刚开始连题目意思都读错 以为是输入的不一定是长度相等的char数组,又搞麻烦了一通
2.是对输入的gets 函数不清楚,用自己的想法去弄 cin但发现cin不能以换行结束输入
3.且对char数组中的0字符与数组的未定义反斜杠0不清晰,这个是关键的判断条件
程序如下:

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
 char a[1000], b[1000];
 gets_s(a);
 gets_s(b);
 for (int i = 0; a[i] != '\0'; i++)
 {
     if (a[i] == b[i])cout << '0';
     else cout << '1';
 }
    system("pause");
    return 0;
}

相关文章

  • 2019-01-22-B二进制异或问题

    Shapur was an extremely gifted student. He was great at e...

  • 位运算--异或(^)

    异或(^)运算 --同为假,异为真 异或结果: (二进制数字) 11 ^ 11 ->00 10 ^ 01 ->1...

  • 笔记

    Java中常用的计算方法 Java异或运算总结 异或运算的性质: 异或运算是基于二进制的位运算,采用符号XO...

  • 异或问题

    异或的作用:0+1=1 ,0+0=0或者1+1=0输入描述:第一行一个数字n第二行n个数字 输出描述:输出最多的...

  • 异或学习

    异或符号:^ 举例:5^2^3 1.转换二进制,5(0101),2(0010),3(0011); 2.异或比较,...

  • 运算符问题

    XOR - 异或 异或:相同为0,不同为1。也可用二进制的不进位加法来理解。 异或操作的一些特点: 指定位置的运算...

  • 使用异或运算符 ^ 互换两个变量的值

    出处 二进制位运算符 - JavaScript 教程 - 网道 ---- 异或运算符 代码 “异或运算”有一个特殊...

  • MySQL语法模板 函数:统计

    MySQL语法模板系列 平均值 二进制按位与 二进制按位或 二进制按位异或 统计二进制1的个数 统计记录数 分组中...

  • 2018-01-28 使用异或操作实现两个数的交换

    原理:异或操作,对于二进制位:如果a、b两个值不相同,则异或结果为1。如果a、b两个值相同,异或结果为0。对于十进...

  • &(按位与) |(按位或) ^(异或)

    不论是&、|还是^都是以二进制的形式进行比较 &(按位与) |(按位或) ^(异或)

网友评论

      本文标题:2019-01-22-B二进制异或问题

      本文链接:https://www.haomeiwen.com/subject/cfhrjqtx.html