Advertisement
ec1117

Untitled

Feb 6th, 2022
932
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.27 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     int n, k;cin>>n>>k;
  7.     int tmp=0;
  8.     for(int i=0;i<n;i++){
  9.         string S;cin>>S;
  10.         if(tmp+S.size()>k){
  11.             cout<<endl;
  12.             tmp=S.size();
  13.         } else {
  14.             if(tmp)cout<<" ";
  15.             tmp+=S.size();
  16.         }
  17.         cout<<S;
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement