[2457일] A. Ultra-Fast Mathematician (성공)

SparklingJustForYou·약 10시간 전

코드포스 공부기록

목록 보기
23/23

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

cpp

#include<iostream>
#include<string>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string a,b;
	cin >> a >> b;
	for (int i = 0; i < a.length(); i++)
	{
		if (a[i] == b[i])cout << 0;
		else cout << 1;
	}
	return 0;
}

c#

using System;
using System.IO;
using System.Text;
using System.Threading;
class Program
{
    static BufferedStream sb = new BufferedStream(Console.OpenStandardInput());
    static StreamReader sr = new StreamReader(new BufferedStream(Console.OpenStandardInput()), Encoding.Default);
    static StreamWriter sw = new StreamWriter(new BufferedStream(Console.OpenStandardOutput()), Encoding.Default);
    static int[] prime = new int[51];
    static int ReadInt()
    {
        int c = sb.ReadByte();
        while (c <= 32) { if (c == -1) return -1; c = sb.ReadByte(); }
        bool neg = false;
        if (c == '-') { neg = true; c = sb.ReadByte(); }
        int val = 0;
        while (c > 32)
        {
            val = val * 10 + (c - '0');
            c = sb.ReadByte();
        }
        return neg ? -val : val;
    }
    static void Solve()
    {
        string a = sr.ReadLine();
        string b = sr.ReadLine();
        for (int i = 0; i < a.Length; i++)
        {
            if (a[i]== b[i]) sw.Write(0);
            else sw.Write(1);
        }
        sw.Flush();
    }
    static void Main(string[] args)
    {
        Thread thread = new Thread(Solve, 1024 * 1024 * 32);
        thread.Start();
        thread.Join();
    }
}

python3

import sys
input = sys.stdin.readline
a=input().rstrip()
b=input().rstrip()
for x,y in zip(a,b):
    if x==y :
        print(0,end="");
    else:
        print(1,end="")

not only A but (also) B:
A~뿐만 아니라 B 했다.

헷갈린 문장:
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.

the ~differ 여기까지가 주어진 위의 입력 숫자란 뜻..

솔직히 예제보면 무슨 문제인지는 앎;;

0개의 댓글