Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define N 1001
- #define M 10001
- using namespace std;
- ifstream fin("date.in");
- ofstream fout("date.out");
- char s[M], cuv[101][N],*p;
- short int a[101][N],b[101][N];
- int L,ct,n, S;
- void Pcta()
- {
- fin>>L;fin.get();
- fin.getline(s, M);
- p=strtok(s," ");
- strcpy(cuv[ct],"");
- while(p)
- {
- n=strlen(p);
- if(S+n+1<=L)
- {
- strcat(cuv[ct],p);
- strcat(cuv[ct]," ");
- S+=n+1;
- }
- else
- {
- ct++;
- strcat(cuv[ct],p);
- strcat(cuv[ct]," ");
- S=n+1;
- }
- p=strtok(0," ");
- }
- for(int i=0;i<=ct;i++)
- fout<<cuv[i]<<"\n";
- fout<<'\n';
- }
- int main()
- {
- Pcta();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment