Advertisement
force1987

28/04

Apr 28th, 2021
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #include<ctime>
  4. #define zadanie 3
  5.  
  6. int main()
  7. {
  8. srand(time(NULL));
  9. setlocale(LC_ALL, "RUS");
  10. #if zadanie == 1
  11. int M, N;
  12. cout << "Введите количество строк:";
  13. cin >> M;
  14. cout << "Введите количество столбцов:";
  15. cin >> N;
  16. char** ptr = new char* [M];
  17. for (int i = 0; i < M; i++) {
  18. ptr[i] = new char[N];
  19. for (int j = 0; j < N; j++) {
  20. ptr[i][j] = 48;
  21. cout << ptr[i][j] << " ";
  22. }
  23. cout << endl;
  24. }
  25. int x, y;
  26. char sym;
  27. cout << "Введите номер строки для разделяющего символа: ";
  28. cin >> x;
  29. cout << "Введите номер столбца для разделяющего символа: ";
  30. cin >> y;
  31. cout << "Введите разделяющий символ: ";
  32. cin >> sym;
  33. ptr[x][y] = sym;
  34. for (int i = 0; i < x; i++) {
  35. for (int j = 0; j < y; j++) {
  36. ptr[i][j] = 49;
  37. }
  38. }
  39. for (int i = 0; i < x; i++) {
  40. for (int j = y + 1; j < N; j++) {
  41. ptr[i][j] = 50;
  42. }
  43. }
  44. for (int i = x + 1; i < M; i++) {
  45. for (int j = 0; j < y; j++) {
  46. ptr[i][j] = 51;
  47. }
  48. }
  49. for (int i = x + 1; i < M; i++) {
  50. for (int j = y + 1; j < N; j++) {
  51. ptr[i][j] = 52;
  52. }
  53. }
  54. for (int i = 0; i < M; i++) {
  55. for (int j = 0; j < N; j++) {
  56. cout << ptr[i][j] << " ";
  57. }
  58. cout << endl;
  59. }
  60. #elif zadanie ==2
  61. int size, N, M, a, b, count;
  62. cout << "Введите размер массива: ";
  63. cin >> size;
  64. cout << "Введите диапазон возможных значений от и до: ";
  65. cin >> a >> b;
  66. int* arr = new int[size];
  67. for (int i = 0; i < size; i++) {
  68. arr[i] = a + rand() % (b - a + 1);
  69. cout << arr[i] << " ";
  70. }
  71. cout << endl;
  72. cout << "На какое количество массивов разбить: ";
  73. cin >> count;
  74. N = (ceil)((double)size / count);
  75. int** ptr = new int* [count];
  76. int ctr = 0;
  77. for (int i = 0; i < count - 1; i++) {
  78. ptr[i] = new int[N];
  79. for (int j = 0; j < N; j++) {
  80. ptr[i][j] = arr[ctr++];
  81. cout << ptr[i][j] << " ";
  82. }
  83. cout << endl;
  84. }
  85. for (int i = count - 1; i < count; i++) {
  86. ptr[i] = new int[size - ctr];
  87. if (ctr < size) {
  88. for (int j = 0; ctr < size; j++) {
  89. ptr[i][j] = arr[ctr++];
  90. cout << ptr[i][j] << " ";
  91. }
  92. }
  93. else {
  94. for (int j = 0; j<N; j++) {
  95. ptr[i][j] = 0;
  96. cout << ptr[i][j] << " ";
  97. }
  98. }
  99. cout << endl;
  100. }
  101. #elif zadanie == 3
  102. /*int* mass = new int[3 + rand() % 18];
  103. for (int i = 0; i < _msize(mass) / sizeof(int); i++) {
  104. mass[i] = rand() % 10;
  105. cout << mass[i] << " ";
  106. }
  107. cout << endl;*/
  108. int size;
  109. cout << "Введите размер массива: ";
  110. cin >> size;
  111. int* mass = new int[size];
  112. for (int i = 0; i < _msize(mass) / sizeof(int); i++) {
  113. cin >> mass[i];
  114. }
  115. cout << endl;
  116. int* ptr = mass;
  117. int sum = 0;
  118. while (ptr <= &mass[(_msize(mass) / sizeof(int)) - 1]) {
  119. cout << sum << endl;
  120. sum += *ptr;
  121. if (ptr == &mass[(_msize(mass) / sizeof(int)) - 1])break;
  122. if (ptr == &mass[(_msize(mass) / sizeof(int)) - 1] - 1)ptr = ptr + 1;
  123. else if (ptr == &mass[(_msize(mass) / sizeof(int)) - 1] - 2) { ((*(ptr + 1)) > (*(ptr + 2)) ? ptr += 1 : ptr += 2); }
  124. else if ((*(ptr + 1)) > (*(ptr + 2)) && (*(ptr + 1)) > 0)ptr += 1;
  125. else if ((*(ptr + 2)) > 0)ptr += 2;
  126. else if ((*(ptr + 1) + *(ptr + 3)) > (*(ptr + 2) + *(ptr + 4)))ptr += 1;
  127. else ptr += 2;
  128. }
  129. cout <<"Результат:"<< sum;
  130. #endif
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement