Advertisement
nicuvlad76

Untitled

Jan 19th, 2021
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 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. int maxi;
  13. void Pcta()
  14. {
  15. fin>>L;
  16. fin.get();
  17. fin.getline(s, M);
  18. p=strtok(s," ");
  19. strcpy(cuv[ct],"");
  20. while(p)
  21. {
  22. n=strlen(p);
  23. if(S+n+1<=L)
  24. {
  25. strcat(cuv[ct],p);
  26. strcat(cuv[ct]," ");
  27. S+=n+1;
  28. }
  29. else
  30. {
  31. ct++;
  32. strcat(cuv[ct],p);
  33. strcat(cuv[ct]," ");
  34. S=n+1;
  35. }
  36. p=strtok(0," ");
  37. }
  38. for(int i=0; i<=ct; i++)
  39. fout<<cuv[i]<<"\n";
  40.  
  41. fout<<'\n';
  42.  
  43. }
  44. void Pctb()
  45. {
  46. int ok=0;
  47. for(int i=0; i<=ct && !ok; i++)
  48. for(int j=0; cuv[i][j] && !ok; j++)
  49. if(cuv[i][j]==' ' && (cuv[i+1][j]==' '||cuv[i+1][j-1]==' '|| cuv[i+1][j+1]==' '))
  50. ok=1;
  51. if(ok==1) fout<<"DA\n" ;
  52. else fout<<"NU\n";
  53. }
  54.  
  55. ///Fill
  56. void Fill(int i, int j ,int k)
  57. {
  58. if(i>ct)return;
  59. if(a[i][j]==0)
  60. {
  61. a[i][j]=k;
  62. if(maxi<k) maxi=k;
  63. ///autoapel
  64. if(j>=0)Fill(i+1,j-1,k+1);
  65. Fill(i+1,j,k+1);
  66. if(j<strlen(cuv[i+1]))Fill(i+1,j+1,k+1);
  67.  
  68. }
  69. }
  70. void Copie(short int a[][N], short int b[][N])
  71. {
  72. for(int i=0;i<=ct;i++)
  73. for(int j=0;cuv[i][j];j++)
  74. a[i][j]=b[i][j];
  75. }
  76. void Pctc()
  77. {
  78. ///matricea
  79. for(int i=0;i<=ct;i++)
  80. for(int j=0;cuv[i][j];j++)
  81. if(cuv[i][j]==' ')a[i][j]=b[i][j]=0;
  82. else a[i][j]=b[i][j]=1;
  83. for(int i=0;i<=ct;i++)
  84. for(int j=0;cuv[i][j];j++)
  85. if(a[i][j]==0)
  86. {
  87. int k=1;
  88. Fill(i,j,k);
  89. Copie(a,b);
  90. }
  91. fout<<maxi;
  92. }
  93. int main()
  94. {
  95. Pcta();
  96. Pctb();
  97. Pctc();
  98. return 0;
  99. }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement