A 가 항상 B 보다 문자갯수가 적거나 같다. 그러니 문자 갯수 차이를 구하고 그만큼 1씩 오른쪽으로 보내면서 A를 B 와 비교하면서 최소값을 구한다.
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string a, b;
cin >> a >> b;
int num2 = 50;
int sizeM = b.size() - a.size();
for (int i = 0; i <= sizeM; ++i)
{
int num = 0;
for (int j = 0; j < a.size() ; ++j)
{
if (a[j] != b[i + j])
{
num++;
}
}
if (num2 >= num)
{
num2 = num;
}
}
cout << num2 << "\n";
return 0;
}
'코딩 테스트' 카테고리의 다른 글
백준 1316 : 그룹 단어 체커 (0) | 2025.03.02 |
---|---|
프로그래머스 - 섬 연결하기 (1) | 2024.11.15 |
백준 1644 소수의 연속합 (0) | 2024.11.15 |
백준 - 12865 배낭 문제 (0) | 2024.11.13 |
백준 1010 - 다리 놓기 (0) | 2024.11.11 |