- 난이도: 브론즈 2
- 알고리즘: 문자열
먼저 겹치는 단어를 찾고, 해당 단어의 좌표의 상하좌우에 단어를 출력하면 된다. 처음에는 어려워 보였지만 생각보다 구현이 간단한 문제였다.
#include <iostream>
#include <deque>
#include <algorithm>
#include <string>
using namespace std;
int main() {
cin.tie(NULL);
cout.tie(NULL);
std::ios::sync_with_stdio(false);
string s1, s2;
cin >> s1 >> s2;
char target;
bool flag = false;
for (char c1 : s1) {
for (char c2 : s2) {
if (c1 == c2) {
target = c1;
flag = true;
}
if (flag) break;
}
if (flag) break;
}
int x = s2.find(target);
int y = s1.find(target);
for (int i = 0; i < s2.length(); i++) {
for (int j = 0; j < s1.length(); j++) {
if (i == x) {
cout << s1[j];
}
else if (j == y) {
cout << s2[i];
}
else {
cout << ".";
}
}
cout << "\n";
}
}