Advertisement
hopingsteam

Untitled

Mar 30th, 2020
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin("fisier.txt");
  8.  
  9. void subpctA()
  10. {
  11. int L = 22;
  12. char text[10005] = "PROBLEMA DE LA EXAMEN NU MI SE PARE FOARTE GREU DE REZOLVAT IN TIMPUL ACORDAT";
  13.  
  14. int litereFolosite = 0; // pe o linie
  15. char *cuvant = strtok(text, " ");
  16. while(cuvant)
  17. {
  18. if(litereFolosite == 0)
  19. {
  20. cout << cuvant << " ";
  21. litereFolosite = strlen(cuvant) + 1;
  22. }
  23. else
  24. {
  25. if(litereFolosite + strlen(cuvant) <= L)
  26. {
  27. cout << cuvant << " ";
  28. litereFolosite = litereFolosite + strlen(cuvant) + 1;
  29. }
  30. else
  31. {
  32. cout << "\n";
  33. cout << cuvant << " ";
  34. litereFolosite = strlen(cuvant) + 1;
  35. }
  36. }
  37. cuvant = strtok(NULL, " ");
  38. }
  39. }
  40.  
  41. void subpctB() {
  42. int L = 22;
  43. int N = 4;
  44.  
  45. char mat[100][10005];
  46. int contor = 0;
  47. for(int i = 0; i < N - 1; i++)
  48. {
  49. int linUrm = strlen(mat[i + 1]);
  50. for(int j = 1; mat[i][j] != '\0'; j++)
  51. {
  52. cout << mat[i][j] << " ";
  53. if(mat[i][j] == ' ')
  54. {
  55. if(mat[i + 1][j] == ' ' && j < linUrm)
  56. {
  57. contor = 1;
  58. break;
  59. }
  60. if(mat[i + 1][j - 1] == ' ' && j - 1 < linUrm)
  61. {
  62. contor = 1;
  63. break;
  64. }
  65. if(mat[i + 1][j + 1] == ' ' && j + 1 < linUrm)
  66. {
  67. contor = 1;
  68. break;
  69. }
  70. }
  71. }
  72. if(contor != 0)
  73. break;
  74. //cout << "\n";
  75. }
  76. }
  77.  
  78. int rau[100][10005];
  79.  
  80. void subpctC() {
  81. int L = 22;
  82. int N = 4;
  83.  
  84. char mat[100][10005];
  85.  
  86.  
  87. for(int i = 0; i < N; i++)
  88. {
  89. fin.getline(mat[i], 10005);
  90. }
  91.  
  92. for(int j = 0; j < strlen(mat[0]); j++)
  93. if(mat[0][j] == ' ')
  94. rau[0][j] = 1;
  95.  
  96. int rauMax = 0;
  97. for(int i = 1; i < N; i++)
  98. {
  99. for(int j = 0; mat[i][j] != '\0'; j++)
  100. {
  101. if(mat[i][j] == ' ')
  102. {
  103. int posMax = 0; //posibilitate maxima
  104. if(rau[i - 1][j - 1] != 0 && rau[i - 1][j - 1] > posMax)
  105. posMax = rau[i - 1][j - 1];
  106. if(rau[i - 1][j] != 0 && rau[i - 1][j] > posMax)
  107. posMax = rau[i - 1][j];
  108. if(rau[i - 1][j + 1] != 0 && rau[i - 1][j + 1] > posMax)
  109. posMax = rau[i - 1][j + 1];
  110. rau[i][j] = 1 + posMax;
  111. if(rau[i][j] > rauMax)
  112. rauMax = rau[i][j];
  113. }
  114. }
  115. }
  116. if(rauMax != 1 && rauMax != 0)
  117. cout << rauMax << "\n";
  118. else
  119. cout << -1;
  120. }
  121.  
  122. int main()
  123. {
  124. for(int i = 0; i < N; i++)
  125. {
  126. for(int j = 0; mat[i][j] != '\0'; j++)
  127. {
  128. cout << rau[i][j] << " ";
  129. }
  130. cout << "\n";
  131. }
  132. return 0;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement