fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int const WORDMAXSIZE = 21, MAXROWS = 101;
  6.  
  7. int main() {
  8. int n, x, y, page = 0, newRowStartingPoint = 0, stars = 0, rowSize = 0,spaces = 0,packStars=0,bonus=0;
  9. char words[MAXROWS][WORDMAXSIZE];
  10. bool a = false;
  11.  
  12. cin >> n >> x >> y;
  13.  
  14. for (int i = 0; i < n; ++i)
  15. cin >> words[i];
  16.  
  17. for (int i = 0; i < n; ++i) {
  18. size_t const wordSize = strlen(words[i]);
  19.  
  20. if (rowSize + wordSize <= y) {
  21. rowSize += wordSize + 1;
  22. ++stars;
  23. a = true;
  24. }
  25. else {
  26. a = false;
  27. spaces = stars - 1;
  28. stars += y - rowSize;
  29.  
  30. if (spaces != 0) {
  31. packStars = stars / spaces;
  32. bonus = stars % spaces;
  33. }
  34.  
  35. for (int j = newRowStartingPoint; j < i; ++j) {
  36. cout << words[j];
  37.  
  38. if (j < i - 1) {
  39. int stopBonus = 0;
  40. if (j < bonus)
  41. stopBonus = 1;
  42.  
  43. for (int k = 0; k < packStars + stopBonus; ++k)
  44. cout << "*";
  45. }
  46. }
  47.  
  48. cout << "\n";
  49. newRowStartingPoint = i;
  50. rowSize = wordSize + 1;
  51. stars = 1;
  52. spaces = 0;
  53. packStars = 0;
  54. bonus = 0;
  55.  
  56. ++page;
  57. if (page == x) {
  58. page = 0;
  59. cout << "\n";
  60. }
  61. }
  62. }
  63.  
  64. if (a) {
  65. spaces = stars - 1;
  66. stars += y - rowSize;
  67.  
  68. if (spaces != 0) {
  69. packStars = stars / spaces;
  70. bonus = stars % spaces;
  71. }
  72. }
  73. for (int j = newRowStartingPoint; j < n; ++j) {
  74. cout << words[j];
  75.  
  76. if (j < n - 1) {
  77. int stopBonus = 0;
  78. if (j < bonus)
  79. stopBonus = 1;
  80.  
  81. for (int k = 0; k < packStars + stopBonus; ++k)
  82. cout << "*";
  83. }
  84. }
  85.  
  86. return 0;
  87. }
Success #stdin #stdout 0.01s 5324KB
stdin
9 5 10
Afara
este
foarte
cald.
Nu
mergem
astazi
la
padure!
stdout
Afara*este
foarte
cald.***Nu
mergem
astazi**la

padure!