Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- #include <vector>
- using namespace std;
- int main() {
- vector<string> lines;
- unsigned int max_length = 0;
- while (!cin.eof()) {
- string line;
- getline(cin, line);
- lines.push_back(line);
- unsigned int line_length = line.length();
- if (max_length < line_length) max_length = line.length();
- }
- for (unsigned int i=0; i<max_length+2; i++) cout << '*';
- cout << endl;
- bool flag = true;
- unsigned int line_count = lines.size();
- for (int j=0; j<line_count; j++) {
- cout << '*';
- unsigned int line_length = lines[j].length();
- unsigned int delta = max_length - line_length;
- unsigned int right_spaces = delta >> 1, left_spaces = delta >> 1;
- if (delta&1) {
- if (flag) right_spaces++;
- else left_spaces++;
- flag = !flag;
- }
- for (unsigned int i=0; i<left_spaces; i++) cout << ' ';
- cout << lines[j];
- for (unsigned int i=0; i<right_spaces; i++) cout << ' ';
- cout << '*';
- cout << endl;
- }
- for (unsigned int i=0; i<max_length+2; i++) cout << '*';
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement