forked from orazaro/accelerated
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05-05-center-pic.cpp
More file actions
44 lines (39 loc) · 1.04 KB
/
05-05-center-pic.cpp
File metadata and controls
44 lines (39 loc) · 1.04 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
#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> center(const std::vector<std::string>& v)
{
vector<string> ret;
string::size_type maxlen = 80;
for(std::vector<std::string>::const_iterator iter = v.begin();
iter != v.end(); ++iter) {
string::size_type len = (maxlen - iter->size()) / 2;
ret.push_back(string(len,' ') + (*iter) + string(len,' '));
}
return ret;
}
int main()
{
// read data
vector<string> v,f;
string line;
while(getline(cin, line))
v.push_back(line);
f = center(v);
out(f);
}