STANAANDREY

ue46

Feb 6th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main ()
  7. { bool ok=true;
  8.     //ofstream fout("data.out");
  9.  ifstream fin("data.in");
  10.   string text,all,aux;
  11.   unsigned short i,cont1=0,len,L,nr=1,poz;
  12.   cin>>L;
  13.   while (getline(fin,text))
  14.  {
  15.  for (i=0;i<text.size();i++)
  16.  {
  17.   if (text[i]!=32)
  18.      {
  19.          all+=text[i];cont1++;
  20.      }
  21.      else
  22.      {  if (ok)
  23.          i++; ok=false;
  24.          len=0;cont1++;aux=" ";poz=i;
  25.          while (text[i]!=32)
  26.          {
  27.              len++;
  28.              aux+=text[i];
  29.              i++;
  30.          }
  31.          if (len+cont1<=L)
  32.          {   cont1+=len;
  33.              all+=aux;i--;
  34.              }
  35.          else
  36.          {
  37.              all+="\n-------\n";
  38.              nr++;cont1=0;
  39.              i=poz;
  40.          }
  41.      }
  42.  
  43.  }
  44.  
  45.  }
  46.  cout<<nr<<endl<<all;
  47.  
  48.  return 0;
  49. }
Add Comment
Please, Sign In to add comment