-
Notifications
You must be signed in to change notification settings - Fork 13
/
frame-the-picture.cpp
35 lines (27 loc) · 1.04 KB
/
frame-the-picture.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <bits/stdc++.h>
int main() {
std::string pattern, padding;
std::getline(std::cin, pattern);
auto reverse_pattern{pattern}, reverse_padding{padding};
std::reverse( std::begin(reverse_pattern), std::end(reverse_pattern));
int h, w, p(pattern.size());
std::cin >> h >> w; std::cin.ignore();
std::vector<std::string> frame(h), border;
for ( auto& l : frame ) {
getline(std::cin, l);
l.resize(w, ' ');
}
for ( auto i = 0; i <= p; ++i ) {
auto line = std::string( w + 2 * ( 1 + p - i), i < p ? pattern[i] : ' ' );
padding = pattern.substr(0, i);
reverse_padding = padding;
std::reverse(std::begin(reverse_padding), std::end(reverse_padding));
line = padding + line + reverse_padding;
border.insert(std::begin(border), line);
std::cout << line << "\n";
}
for ( auto& l : frame )
std::cout << pattern + " " + l + " " + reverse_pattern << "\n";
for ( auto& l : border )
std::cout << l << "\n";
}