Advertisement
NgJaBach

Word Processor

Jan 23rd, 2023 (edited)
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. // NgJaBach: Forever Meadow <3
  2.  
  3. #include<bits/stdc++.h>
  4.  
  5. using namespace std;
  6. typedef long long int ll;
  7. typedef unsigned long long ull;
  8. #define pb push_back
  9. #define pob pop_back
  10. #define mp make_pair
  11. #define upb upper_bound
  12. #define lwb lower_bound
  13. #define bend(a) a.begin(),a.end()
  14. #define rev(x) reverse(bend(x))
  15. #define mset(a) memset(a, 0, sizeof(a))
  16. #define fi first
  17. #define se second
  18. #define gcd __gcd
  19. #define getl(s) getline(cin, s);
  20. #define setpre(x) fixed << setprecision(x)
  21. #define endl '\n'
  22. const int N=200050,M=1000000007;
  23. const ll INF=1e18+7;
  24. int main(){
  25.     ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
  26.     freopen("word.in","r",stdin);
  27.     freopen("word.out","w",stdout);
  28.     int n,k,cnt=0,m;
  29.     string s,str;
  30.     str.clear();
  31.     cin>>n>>k;
  32.     for(int i=0;i<n;++i){
  33.         cin>>s;
  34.         m=s.size();
  35.         if(cnt+m<=k){
  36.             cnt+=m;
  37.             if(!str.empty()) str.pb(' ');
  38.             str+=s;
  39.         }
  40.         else{
  41.             cout<<str<<endl;
  42.             str=s; cnt=m;
  43.         }
  44.     }
  45.     cout<<str;
  46.     return 0;
  47. }
  48. /*
  49. ==================================+
  50. INPUT:                            |
  51. ------------------------------    |
  52.  
  53. ------------------------------    |
  54. ==================================+
  55. OUTPUT:                           |
  56. ------------------------------    |
  57.  
  58. ------------------------------    |
  59. ==================================+
  60. */
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement