본문 바로가기
  • Let's study
알고리즘/C++

[백준] 3449: 해밍 거리(C++)

by 코딩고수이고파 2025. 4. 18.

문제

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

코드

#include <iostream>
#include <string>

using namespace std;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t;
	string a, b;

	cin >> t;

	for (int i = 0; i < t; i++) {
		cin >> a >> b;

		int cnt = 0;
		for (int j = 0; j < a.size(); j++) {
			if (a[j] != b[j])
				cnt++;
		}

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

	return 0;
}

'알고리즘 > C++' 카테고리의 다른 글

[C++] 문자열 분리하기(split)  (0) 2023.10.14
[알고리즘] 백트레킹  (0) 2023.10.05
[알고리즘] 다익스트라  (0) 2023.10.02
[알고리즘] 이분 탐색  (0) 2023.10.01
[알고리즘] 탐욕(그리디) 알고리즘  (0) 2021.11.01

댓글