IMohammedNasr

Untitled

Mar 14th, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. int Maxx = 0, i = 0;
  2. vector<string> s;
  3. string holder;
  4. while (getline(cin, holder))
  5. {
  6. s.push_back(holder);
  7. int x = holder.length();
  8. Maxx = max(Maxx, x);
  9. }
  10. int t = Maxx + 2;
  11. while (t--)
  12. cout << "*";
  13. cout << endl;
  14. bool flag = true;
  15. for (auto &i : s)
  16. {
  17. int l, r;
  18. if (i.length() != Maxx)
  19. {
  20. if (flag and (Maxx - i.length() - 2) % 2)
  21. {
  22. l = ((Maxx - i.length()) % 2 ? (Maxx - i.length()) / 2 + 1 : (Maxx - i.length()) / 2), r = Maxx - l - i.length();
  23. if (l + r != Maxx)
  24. flag = false;
  25. }
  26. else
  27. {
  28. r = ((Maxx - i.length()) % 2 ? (Maxx - i.length()) / 2 + 1 : (Maxx - i.length()) / 2), l = Maxx - r - i.length();
  29. if (l + r != Maxx)
  30. flag = true;
  31. }
  32. cout << "*";
  33. while (r--)
  34. cout << " ";
  35. cout << i;
  36. while (l--)
  37. cout << " ";
  38. cout << "*" << endl;
  39. }
  40. else
  41. {
  42. cout << "*" << i << "*" << endl;
  43. }
  44. }
  45. t = Maxx + 2;
  46. while (t--)
  47. cout << "*";
Advertisement
Add Comment
Please, Sign In to add comment