special_forces

Untitled

May 18th, 2021
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <math.h>
  3. #include <cstdio>
  4. #include <locale.h>
  5. #include <iostream>
  6. #include < cstdlib >
  7.  
  8.  
  9. int main() {
  10.     setlocale(LC_ALL, "Russian");
  11.     int size,str;
  12.     printf("Введите  количество строк\n");
  13.     scanf("%d", &str);
  14.     printf("Введите  количество столбцов\n");
  15.     scanf("%d", &size);
  16.     int** arr = new int* [str];
  17.     for (int i = 0; i < str; i++) {
  18.         arr[i] = new int[size];
  19.     }
  20.     printf("Введите  значения матрицы\n");
  21.     for (int i = 0;i < str;i++) {
  22.         for (int j = 0;j < size;j++) {
  23.             printf("arr[%d][%d] ", i, j);
  24.                 scanf("%d", &arr[i][j]);
  25.         }
  26.         printf("\n");
  27.     }
  28.     printf("-----------\n");
  29.     for (int i = 0; i < str; i++)
  30.     {
  31.         for (int j = 0; j < size; j++)
  32.         {
  33.             printf("arr[%d][%d] %d ",i, j, arr[i][j]);
  34.         }
  35.         printf("\n");
  36.     }
  37.     int count = 0;
  38.     for (int j = 0; j < size; j++)//int j = 0; j < size; j++
  39.     {
  40.         for (int i = 0; i < str; i++)
  41.         {
  42.             if (arr[i][j]==0) {
  43.                 count = count + 1;
  44.                 break;
  45.             }
  46.         }
  47.         printf("\n");
  48.     }
  49.     printf("Количество столбцов ,в которых хотя бы есть один нолик.%d\n", count);
  50.     int max=0,count_max = 0,count_t = 0;
  51.     int t = 0, t_idx;
  52.     for (int i = 0; i < str; i++){
  53.         count_t = 1;
  54.         t_idx = i;
  55.         for (int j = i + 1; j < size; j++)  
  56.         {
  57.             if (arr[i] == arr[i + 1])
  58.             {
  59.                 count_t++;
  60.                 if (count_t > t)
  61.                     t = count_t;
  62.             }
  63.             else
  64.                 count_t = 0;
  65.         }
  66.         if (t > count_max) {
  67.             count_max = t;
  68.             max = t_idx;
  69.         }
  70.     }
  71.     printf("Строчка в которой находиться самая длинная серия:%d\n", max);
  72.     for (int i = 0; i < str; i++) {
  73.    
  74.         delete[] arr[i];
  75.     }
  76.     delete[] arr;
  77.  
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment