Ultra-Fast Mathematician

举报
辰chen 发表于 2022/06/14 22:54:46 2022/06/14
【摘要】 文章目录 一、Ultra-Fast Mathematician总结 一、Ultra-Fast Mathematician 本题链接:Ultra-Fast Mathematician ...


一、Ultra-Fast Mathematician

本题链接Ultra-Fast Mathematician

题目
A. Ultra-Fast Mathematician
time limit per test2 seconds
memory limit per test256 megabytes
nputstandard input
outputstandard output
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

本博客给出本题截图

题意:输入两个数,如果对应位置上分别是01的话,输出1,否则为0

AC代码

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string a, b;
    cin >> a >> b;
    
    for (int i = 0; i < a.size(); i ++ )
        if (a[i] + b[i] == '1' + '0')
            cout << 1;
        else cout << 0;
    
    return 0;
}

总结

其实就是二进制异或运算

文章来源: chen-ac.blog.csdn.net,作者:辰chen,版权归原作者所有,如需转载,请联系作者。

原文链接:chen-ac.blog.csdn.net/article/details/117516625

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。