Bob103

римская 4 массив

Dec 22nd, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int **creat(int &n, int &m)
  6. {
  7. int **mas = new int*[n];
  8. for (int i = 0; i < n; ++i)
  9. mas[i] = new int[m];
  10. for (int i = 0; i < n; ++i)
  11. for (int j = 0; j < m; ++j)
  12. {
  13. cout << "mas[" << i << "][" << j << "]=";
  14. cin >> mas[i][j];
  15. }
  16. return mas;
  17. }
  18.  
  19. int main()
  20. {
  21. int n, m;
  22.  
  23. cout << "n=";
  24. cin >> n;
  25. cout << "m=";
  26. cin >> m;
  27.  
  28. int **a = creat(n, m);
  29. int* out = new int [n];
  30. for (int i = 0; i < n; ++i)
  31. {
  32. int cnt = 1;
  33. for (int j = 0; j < m - 1; ++j)
  34. {
  35. if (a[i][j] != a[i][j + 1])
  36. {
  37. out[i] = cnt;
  38. break;
  39. }
  40. else
  41. cnt++;
  42.  
  43. }
  44.  
  45. }
  46. cout << "Received matrix:"<<endl;
  47. for (int i = 0; i < n; i++)
  48. {
  49. for (int j = 0; j < m; j++)
  50. cout << a[i][j] << " ";
  51. cout << endl;
  52. }
  53.  
  54. cout << "Output array: ";
  55. for(int i = 0; i < n; i++)
  56. cout << out[i] << ' ';
  57. cout << endl;
  58.  
  59. for (int i = 0; i < n; ++i)
  60. delete[]a[i];
  61. delete[]a;
  62.  
  63. system("pause");
  64.  
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment