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

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;
}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,186评论 0 10
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,516评论 0 23
  • 在微博上看到你心目中最好的一部电视剧是什么,我心中好犯难,最好的……我看了底下五花八门的评论,一些看过忘了的电视...
    丑故阅读 1,868评论 0 1
  • 清彻溪水漫流,堤上鲜蕊相守。不畏寒来凉气袭,艳丽娇姿秀。粉红白颜又蕾稠,木芙蓉,举花枝头。傲立岸,任风吹雨打,笑洒...
    龙华之韵阅读 4,140评论 3 2
  • 呼吸的清晨 沉睡的楼 仓促间碎了玻璃 掉出了梦 昨天 有夜幕在撬锁 守门的人 是我 不是我 月色里 谁收得了心神 ...
    晓天晓天阅读 4,119评论 0 0

友情链接更多精彩内容