Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4. #include <algorithm>
  5. #define task "word"
  6. #define ld long double
  7. #define ll long long
  8. #define ull unsigned long long
  9.  
  10. using namespace std;
  11. const int sizearr = 100003;
  12.  
  13. string s[101];
  14. int n, k, cnt, j = 1;
  15.  
  16. inline void fastIOfileinput(){
  17.     ios_base:: sync_with_stdio(0);
  18.     cin.tie(0);
  19.     cout.tie(0);
  20.     if(fopen(task".inp", "r")){
  21.         freopen(task".inp", "r", stdin);
  22.         freopen(task".out", "w", stdout);
  23.     }
  24.     if(fopen(task".in", "r")){
  25.         freopen(task".in", "r", stdin);
  26.         freopen(task".out", "w", stdout);
  27.     }
  28. }
  29.  
  30. inline void subtask(){
  31.     ;
  32. }
  33.  
  34. int main(){
  35.     fastIOfileinput();
  36.     cin >> n >> k;
  37.     for(int i = 1; i <= n; ++i){
  38.         cin >> s[i];
  39.         cnt += s[i].length();
  40.         if(cnt > k){
  41.             for(int t = j; t < i; ++t) cout << s[t] << (t == i - 1 ? "\n" : " ");
  42.             j = i;
  43.             cnt = s[i].length();
  44.         }
  45.     }
  46.     if(cnt <= k){
  47.         for(int t = j; t <= n ; ++t) cout << s[t] << (t == n ? "" : " ");
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement