forked from orazaro/accelerated
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06-00-copy.cpp
More file actions
58 lines (52 loc) · 1.42 KB
/
06-00-copy.cpp
File metadata and controls
58 lines (52 loc) · 1.42 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void out(const std::vector<std::string>& v)
{
for(std::vector<std::string>::const_iterator iter = v.begin();
iter != v.end(); ++iter)
cout << *iter << endl;
}
std::string::size_type width(const std::vector<std::string>& v)
{
string::size_type maxlen = 0;
for(std::vector<std::string>::const_iterator iter = v.begin();
iter != v.end(); ++iter)
maxlen = max(maxlen, iter->size());
return maxlen;
}
std::vector<std::string> frame(const std::vector<std::string>& v)
{
vector<string> ret;
string::size_type maxlen = width(v);
string border(maxlen + 4, '*');
ret.push_back(border);
for(std::vector<std::string>::const_iterator iter = v.begin();
iter != v.end(); ++iter) {
ret.push_back("* " + (*iter) + string(maxlen - iter->size(),' ') + " *");
}
ret.push_back(border);
return ret;
}
std::vector<std::string> vcat(const std::vector<std::string>& top,
const std::vector<std::string>& bottom)
{
vector<string> ret = top;
#if 0
copy(bottom.begin(), bottom.end(), back_inserter(ret));
#else
ret.resize(top.size()+bottom.size());
copy(bottom.begin(), bottom.end(), ret.begin()+top.size());
#endif
return ret;
}
int main()
{
vector<string> v,f;
string line;
while(getline(cin, line))
v.push_back(line);
f = frame(v);
out(vcat(v,f));
}