백준 1120 c++

magicdrill·2024년 2월 23일
0

백준 문제풀이

목록 보기
19/655

백준 1120 c++

#include <iostream>
#include <string>

using namespace std;

void input_two_strings(string *A, string *B)
{
	cin >> *A >> *B;

	return;
}

int find_result(string A, string B)
{
	int A_length = A.length(), B_length = B.length();
	int i, j;
	int min = B_length;
	int count;

	//A 앞뒤로 아무 문자나 집어넣어도 되므로, 기존 A와 B를 비교해 최소값 도출
	for (i = 0; i <= B_length - A_length; i++)
	{
		count = 0;
		for (j = 0; j < A_length; j++)
		{
			if (A[j] != B[j + i])
			{
				count++;
			}
		}
		if (count < min)
		{
			min = count;
		}
	}

	return min;
}

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	string A, B;

	input_two_strings(&A, &B);
	cout << find_result(A, B) << "\n";

	return 0;
}

0개의 댓글