寒假6.2

作者: wolfway_d0ff | 来源:发表于2019-01-30 09:13 被阅读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
本题解题需用到字符串而非数组,定义三个字符串,前两个用于输入,后一个用于写入输出数。

#include<iostream>
using namespace std;
int main()
{
    char a[100], b[100], c[100];
    int i;
    cin >> a;
    for(i=0;a[i]!='\0';i++){}
    for (int j = 0; j < i; j++)
    {
        cin >> b[j];
    }
    for (int j = 0; j < i; j++)
    {
        if (a[j] == b[j])
        {
            c[j] = '0';
        }
        else
            c[j] = '1';
    }
    for(int j=0;j<i;j++)
    cout << c[j];
    return 0;
}

相关文章

  • 寒假6.2

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

  • 【区分精选】合同链测评 —— 这个领域也就只能吹吹技术了

    项目立项 / 25%——6.6 核心团队/ 30%——6.2 社区治理/ 25%——6.2 履约能力/ 20%——...

  • 减肥第81天

    6月2日,周五 6.2晨体重:52.2(晨跑后量) 6.2运动:户外晨跑11公里 6.2饮食:早餐:半碗粥、半根肉...

  • 学习计划

    一个寒假过了,接下来要面临的是一个未知的“新世界”我们要制定好路线,准备好装备,鼓舞起我方的士气,向“6.2...

  • 实验6.2 VLAN基本配置

    6.2 VLAN基本配置 ============================================...

  • 标签-HTML5精讲 课时ID:6.2 【表严肃】【

    6.2 标签-HTML5精讲 课时ID:6.2 【表严肃】#HTML教程 #HTML5教程 #body...

  • 6.2

    木木一人坐在值班室,双肘撑在桌上,眼睛却直直盯着地上那块有个裂角的瓷砖,早餐时只啃了几口面包的她觉得从脑袋到肚子都...

  • 6.2

    1哇呀,我今天想睡几点睡到几点2感谢我的宝贝儿子平安到达老家3感谢我的先生那么爱我,帮我洗好衣服,做好早餐4我感觉...

  • 6.2

    在家休息真好,多一步路都不想走!

  • 6.2

    今天周六,可惜睡到8.30就醒来了。原来睡到11点的功能好像渐渐消失。 昨晚做了很长的梦,梦让我很不安。梦里的人都...

网友评论

      本文标题:寒假6.2

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