[백준/C++] 3449 - 해밍 거리

orangesnail·2025년 8월 23일

백준

목록 보기
149/169

https://www.acmicpc.net/problem/3449


주어진 입력형식을 보면 숫자를 문자열로 입력받아야 한다는 것을 알 수 있다.
이후 반복문을 이용해 문자열의 각 자리를 비교해가며 다른 경우 count를 1 증가시켜주면 된다.

#include <iostream>
using namespace std;

int main() {
    int t;
    cin >> t;

    while (t--) {
        string a, b;
        cin >> a >> b;

        int count = 0;
        for (int i = 0; i < a.size(); i++)
            if (a[i] != b[i]) count++;

        cout << "Hamming distance is " << count << ".\n";
    }

    return 0;
}
profile
초보입니다. 피드백 환영합니다 😗

0개의 댓글