nicuvlad76

Untitled

Jan 19th, 2021
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define N 1001
  3. #define M 10001
  4. using namespace std;
  5.  
  6. ifstream fin("date.in");
  7. ofstream fout("date.out");
  8.  
  9. char s[M], cuv[101][N],*p;
  10. short int a[101][N],b[101][N];
  11. int L,ct,n, S;
  12. void Pcta()
  13. {
  14. fin>>L;fin.get();
  15. fin.getline(s, M);
  16. p=strtok(s," ");
  17. strcpy(cuv[ct],"");
  18. while(p)
  19. {
  20. n=strlen(p);
  21. if(S+n+1<=L)
  22. {
  23. strcat(cuv[ct],p);
  24. strcat(cuv[ct]," ");
  25. S+=n+1;
  26. }
  27. else
  28. {
  29. ct++;
  30. strcat(cuv[ct],p);
  31. strcat(cuv[ct]," ");
  32. S=n+1;
  33. }
  34. p=strtok(0," ");
  35. }
  36. for(int i=0;i<=ct;i++)
  37. fout<<cuv[i]<<"\n";
  38.  
  39. fout<<'\n';
  40.  
  41. }
  42.  
  43. int main()
  44. {
  45. Pcta();
  46. return 0;
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment