Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1.  
  2. #include <string>
  3. #include <iostream>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. vector<string> lines;
  10. unsigned int max_length = 0;
  11. while (!cin.eof()) {
  12. string line;
  13. getline(cin, line);
  14. lines.push_back(line);
  15. unsigned int line_length = line.length();
  16. if (max_length < line_length) max_length = line.length();
  17. }
  18. for (unsigned int i=0; i<max_length+2; i++) cout << '*';
  19. cout << endl;
  20.  
  21. bool flag = true;
  22. unsigned int line_count = lines.size();
  23. for (int j=0; j<line_count; j++) {
  24. cout << '*';
  25. unsigned int line_length = lines[j].length();
  26. unsigned int delta = max_length - line_length;
  27. unsigned int right_spaces = delta >> 1, left_spaces = delta >> 1;
  28. if (delta&1) {
  29. if (flag) right_spaces++;
  30. else left_spaces++;
  31. flag = !flag;
  32. }
  33.  
  34. for (unsigned int i=0; i<left_spaces; i++) cout << ' ';
  35. cout << lines[j];
  36. for (unsigned int i=0; i<right_spaces; i++) cout << ' ';
  37. cout << '*';
  38. cout << endl;
  39. }
  40.  
  41. for (unsigned int i=0; i<max_length+2; i++) cout << '*';
  42. cout << endl;
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement