Advertisement
Mihai_Preda

Untitled

Dec 23rd, 2020
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. /* PROBLEMA DE LA EXAMEN NU MI SE PARE FOARTE GREU DE REZOLVAT IN TIMPUL ACORDAT */
  5. int main()
  6. {
  7.     string s, a;
  8.     int i, L, k=0;
  9.     cin>>L;
  10.     getline(cin, s);
  11.     s=s+' ';
  12.     int j=0;
  13.     for (i=0; i<s.size(); i++)
  14.     {
  15.         if (s[i]!=' ')
  16.         {
  17.             a[j]=s[i];
  18.             j++;
  19.         }
  20.         else
  21.         {
  22.             k=k+a.size();
  23.             if (k<=L)
  24.             {
  25.                 cout <<a<<' ';
  26.                 k++;
  27.                 a=' ';
  28.                 j=0;
  29.             }
  30.             else
  31.             {
  32.                 cout<<endl;
  33.                 cout<<a;
  34.                 k=a.size()+1;
  35.                 a=' ';
  36.                 j=0;
  37.             }
  38.         }
  39.     }
  40.     return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement