首页 » 技术分享 » 抑或

抑或

 

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
题目大意:每个输入有两行。它们中的每一个都包含一个数字。保证数字只由0和1组成,且长度相同。数字可能以0开头。每个数字的长度不超过100。每个数字由数字0或1组成。参赛者应该写一个新的数字对应于给定的一对数字。规则很简单:答案的第一位数是1当且仅当两个给定数字的第一位数不同时。在另一种情况下,答案的第一位数是0。
代码如下(已AC):

#include <cstdio>
#include <memory>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	string s1, s2;
	cin >> s1 >> s2;
	for (int i = 0; i < s1.length(); i++)
		if (s1[i] == s2[i])cout << 0; else cout << 1;
	return 0;
}

转载自原文链接, 如需删除请联系管理员。

原文链接:抑或,转载请注明来源!

0