加载中...

Ultra-Fast Mathematician


Codeforces题解|61A Ultra-Fast Mathematician


题目信息 📚

【题目描述】

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 $10^{18}$ numbers in a single second.

One day in 230 AD, Shapur was trying to find out if anyone could possibly do calculations faster than him. As a result, he made a very great contest and asked everyone 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 could perform these operations on numbers of length $\infty$ (length of a number is the 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 the same length.

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

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 the same. The numbers may start with 0. The length of each number doesn’t exceed 100.

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

【输入】

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 the same. The numbers may start with $0$. The length of each number doesn’t exceed $100$.

【输出】

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

【输入样例1】

1010100
0100101

【输出样例1】

1110001

【输入样例2】

000
111

【输出样例2】

111

【输入样例3】

1110
1010

【输出样例3】

0100

【输入样例4】

01110
01100

【输出样例4】

00010

【题目来源】

https://codeforces.com/problemset/problem/61/A


题目解析 🍉

【题目分析】

手动模拟「异或」运算(不进位加法)。

【C++代码】

#include<bits/stdc++.h>

using namespace std;
typedef long long LL;

int main() {
    string s1, s2;
    cin >> s1 >> s2;

    string res = "";
    for (int i = 0; i < s1.size(); i++) {
        res += (s1[i] == s2[i]) ? '0' : '1';
    }
    cout << res << endl;

    return 0;
}

文章作者: Rickyの水果摊
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Rickyの水果摊 !
  目录