1일1알

백준 1120번 문자열 C++ 본문

알고리즘

백준 1120번 문자열 C++

영춘권의달인 2022. 3. 24. 11:59

출처 : https://www.acmicpc.net/problem/1120

 

A에만 문자를 추가할 수 있기 때문에 b 안에서 a와 가장 비슷한 문자열을 찾았다.

 

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>

using namespace std;
using ll = long long;

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

	string str1, str2;
	cin >> str1 >> str2;

	int ans = 50;
	for (int i = 0; i < str2.length(); i++) {
		if (i + str1.length() > str2.length()) break;
		int cnt = str1.length();
		for (int j = 0; j < str1.length(); j++) {
			if (str2[i + j] == str1[j]) cnt--;
		}
		ans = min(ans, cnt);
	}
	cout << ans;
};