Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <string>
- using namespace std;
- int main ()
- { bool ok=true;
- //ofstream fout("data.out");
- ifstream fin("data.in");
- string text,all,aux;
- unsigned short i,cont1=0,len,L,nr=1,poz;
- cin>>L;
- while (getline(fin,text))
- {
- for (i=0;i<text.size();i++)
- {
- if (text[i]!=32)
- {
- all+=text[i];cont1++;
- }
- else
- { if (ok)
- i++; ok=false;
- len=0;cont1++;aux=" ";poz=i;
- while (text[i]!=32)
- {
- len++;
- aux+=text[i];
- i++;
- }
- if (len+cont1<=L)
- { cont1+=len;
- all+=aux;i--;
- }
- else
- {
- all+="\n-------\n";
- nr++;cont1=0;
- i=poz;
- }
- }
- }
- }
- cout<<nr<<endl<<all;
- return 0;
- }
Add Comment
Please, Sign In to add comment