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

astazi**la
padure!