실패~
하나씩 비교해서 가장 짧은 문자열을 구하려고 했다
그런데 1a2b3c4 와 5a6b3c2이런 경우를 통과 못 했다
a b c 를 사이에 두고
1 5 a 2 6 b 3 c 4 2
이런 경우 막힌다....
모르겠다 포기
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <bitset>
#include <stdio.h>
#include <math.h>
#include <sstream>
#include<cassert>
#include <climits>
#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()
#define MAXV 987654321
using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using iis = pair<int, string>;
using ii64 = pair<i64, i64>;
using iii = tuple<int, int, int>;
string overlappingStr(string origin, string tofind) {
int ans = 0;
string ansStr = origin + tofind;
for (int startIdx = 0; startIdx < tofind.size(); startIdx++) {
string str = "";
for (int i = 0; i < startIdx; i++) {
str += tofind[i];
}
int j = startIdx;
for (int i = 0; i < origin.size(); i++) {
str += origin[i];
if (origin[i] == tofind[j]) {
j++;
}
}
for (; j < tofind.size(); j++) {
str += tofind[j];
}
if (str.size() < ansStr.size()) {
ansStr = str;
}
}
return ansStr;
}
void f(string s1, string s2) {
string ans1 = overlappingStr(s1, s2);
string ans2 = overlappingStr(s2, s1);
if (ans1.size() < ans2.size())
cout << ans1 << endl;
else
cout << ans2 << endl;
}
int main() {
string s1, s2;
while (cin >> s1 >> s2) {
f(s1, s2);
}
return 0;
}
'백준' 카테고리의 다른 글
2778 측량사 지윤 (0) | 2023.04.15 |
---|---|
2900 프로그램 (0) | 2023.03.04 |
12909 그래프 만들기 (0) | 2023.02.11 |
24524 아름다운 문자열 (0) | 2023.01.14 |
23083 꿀벌 승연이 (0) | 2023.01.14 |