Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. task 1
  2.  
  3. /*#include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. void deleteMatrix ( int** matrix , int n )
  8. {
  9. for ( int i=0 ; i<n ; i++ )
  10. {
  11. delete[] matrix[i];
  12. }
  13. delete[] matrix;
  14. }
  15.  
  16. bool compareClms ( int** matrix , int N , int Iindex , int Jindex )
  17. {
  18. for ( int i=0 ; i<N ; i++ )
  19. {
  20. if ( matrix[i][Iindex] != matrix[N-i][Jindex] )
  21. {
  22. return false;
  23. }
  24. }
  25. return true;
  26. }
  27.  
  28. int main()
  29. {
  30. int N,M;
  31. cout << " write the indexes of the matrix ";
  32. cin >> N >> M;
  33. int** matrix = new (nothrow) int* [N];
  34. if ( matrix != nullptr )
  35. {
  36. for ( int i=0 ; i<N ; i++ )
  37. {
  38. matrix[i] = new (nothrow) int[M];
  39. if ( matrix[i] == nullptr )
  40. {
  41. deleteMatrix(matrix,N);
  42. }
  43. }
  44. cout << " fill the matrix " << N << "X" << M << endl;
  45. for ( int i=0 ; i<N ; i++ )
  46. {
  47. for ( int j=0 ; j<M ; j++ )
  48. {
  49. cin >> matrix[i][j];
  50. }
  51. }
  52. int cntr = 0;
  53. for( int i=0 ; i<M ; i++ )
  54. {
  55. int j=M-i;
  56. if ( compareClms(matrix,N,i,j) )
  57. {
  58. cout << i << " " << j << endl;
  59. cntr ++ ;
  60. }
  61. }
  62. if ( cntr == 0 )
  63. {
  64. cout << " NO! " << endl;
  65. }
  66.  
  67.  
  68. }
  69.  
  70. deleteMatrix(matrix,N);
  71.  
  72. return 0;
  73. }
  74. */
  75. task 2
  76. /*#include<iostream>
  77.  
  78. using namespace std;
  79.  
  80. bool compareHelper (unsigned int n1 ,unsigned int n2 )
  81. {
  82. if ( n2 < 0 )
  83. {
  84. return false;
  85. }
  86. if ( n1 % 10 != n2 % 10 )
  87. {
  88. return compareHelper(n1,n2 /10);
  89. }
  90. else
  91. {
  92. return true;
  93. }
  94. }
  95.  
  96. bool compare ( unsigned int num1,unsigned int num2 )
  97. {
  98. if ( num1 < 10 && num2 && num1 == num2 )
  99. {
  100. return true;
  101. }
  102. if ( compareHelper(num1,num2) )
  103. {
  104. return compare(num1/10,num2);
  105. }
  106. else
  107. {
  108. return false;
  109. }
  110.  
  111. }
  112.  
  113. int main () {
  114.  
  115. unsigned int num1,num2;
  116. cout << " write 2 numbers ";
  117. cin >> num1 >> num2;
  118. if( num1 > num2 )
  119. {
  120. swap(num1,num2);
  121. }
  122. if ( compare(num1,num2) )
  123. {
  124. cout << " yes ";
  125. }
  126. else
  127. {
  128. cout << " no ";
  129. }
  130.  
  131. }
  132. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement