Problem--61A--Codeforces--A. Ultra-Fast Mathematician

本文介绍了一个名为“超速数学家”的竞赛,参赛者需要对比两个由0和1组成的等长数字串,并根据规则输出相应的结果。文章提供了两种实现方法,一种通过逐位比较输出‘0’或‘1’,另一种利用异或操作简化处理过程。

A. Ultra-Fast Mathematician
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard 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

思路:将输入的两组数据每位进行比较,相同则在对应位输出’0’,不同则输出’1’,感觉就是每位异或,输出结果

#include<stdio.h>
#include<string.h>
int main(){
    char str1[105],str2[105];
    scanf("%s%s",str1,str2);
    for(int i=0;i<strlen(str1);i++)
    str1[i]=(str1[i]==str2[i])?'0':'1';
    puts(str1);
}
#include<stdio.h>
#include<string.h>
int main(){
    char str1[105],str2[105];
    scanf("%s%s",str1,str2);
    for(int i=0;i<strlen(str1);i++)
    printf("%d",str1[i]^str2[i]);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值