Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int **creat(int &n, int &m)
- {
- int **mas = new int*[n];
- for (int i = 0; i < n; ++i)
- mas[i] = new int[m];
- for (int i = 0; i < n; ++i)
- for (int j = 0; j < m; ++j)
- {
- cout << "mas[" << i << "][" << j << "]=";
- cin >> mas[i][j];
- }
- return mas;
- }
- int main()
- {
- int n, m;
- cout << "n=";
- cin >> n;
- cout << "m=";
- cin >> m;
- int **a = creat(n, m);
- int* out = new int [n];
- for (int i = 0; i < n; ++i)
- {
- int cnt = 1;
- for (int j = 0; j < m - 1; ++j)
- {
- if (a[i][j] != a[i][j + 1])
- {
- out[i] = cnt;
- break;
- }
- else
- cnt++;
- }
- }
- cout << "Received matrix:"<<endl;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- cout << a[i][j] << " ";
- cout << endl;
- }
- cout << "Output array: ";
- for(int i = 0; i < n; i++)
- cout << out[i] << ' ';
- cout << endl;
- for (int i = 0; i < n; ++i)
- delete[]a[i];
- delete[]a;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment