1일1알

백준 1195번 킥다운 C++ 본문

알고리즘

백준 1195번 킥다운 C++

영춘권의달인 2022. 4. 12. 11:40

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

 

왼쪽 끝에서 아예 만나지 않을때부터 오른쪽 끝에서 만나지 않을때까지 비교하면서 

서로 이가 모두 만나지 않는 부분 중에서 가로 너비의 최솟값을 구하였다.

 

#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 = str1.length() + str2.length();
	int offset = str1.length();
	for (int i = -offset; i <= int(str2.length()); i++) {
		bool isAllInterloakced = true;
		for (int j = 0; j < str1.length(); j++) {
			if (i + j >= 0 && i + j < str2.length()) {
				if (str1[j] == '2' && str2[i + j] == '2')isAllInterloakced = false;
			}
		}
		if (isAllInterloakced)
			ans = min(int((max(str2.length(), i + str1.length()) - min(0, i))), ans);
			
	}
	cout << ans;
};

'알고리즘' 카테고리의 다른 글

백준 1213번 팰린드롬 만들기 C++  (0) 2022.04.15
백준 1113번 수영장 만들기 C++  (0) 2022.04.14
백준 1063번 킹 C++  (0) 2022.04.11
백준 1205번 등수 구하기 C++  (0) 2022.04.10
백준 6603번 로또 C++  (0) 2022.04.09