Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. #include <map>
  2. #include <iostream>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. class massive{
  7. private:
  8. int **array;
  9. int rows,colums;
  10. map<int,int> values;
  11. public:
  12.  
  13. massive(const int&q){
  14. rows = colums = q;
  15. array = new int*[q];
  16. for(int i=0;i<q;i++){
  17. array[i] = new int[q];
  18. }
  19.  
  20. }
  21.  
  22. void FillMassive(){
  23. srand(time(NULL));
  24. for(int i=0;i<this->rows;i++){
  25. for(int j=0;j<this->colums;j++){
  26. this->array[i][j] = rand()%10 + 1;
  27. }
  28. }
  29. }
  30. void PrintMap(){
  31. for(const auto&q:values){
  32. cout << q.first << " : " << q.second << endl;
  33. }
  34. cout << "---------------------------------------" << endl;
  35. }
  36. void PrintMapMassive(){
  37. int i=0;
  38. for(const auto&q:values){
  39. for(int j=0;j<q.second;j++){
  40. cout << array[i][j] << " ";
  41. }
  42. cout << endl;
  43. i++;
  44. }
  45. cout << "---------------------" << endl;
  46. }
  47. void FillMassiveMap(){
  48. int i=0;
  49. for(const auto&q:values){
  50. for(int j=0;j<q.second;j++){
  51. array[i][j] = q.first;
  52. }
  53. i++;
  54. }
  55. }
  56. massive(const map<int,int>&values1){
  57. values = values1;
  58. array = new int*[values.size()];
  59. int i=0;
  60. for(const auto&a:values){
  61. array[i] = new int[a.second];
  62.  
  63. i++;
  64. }
  65.  
  66. }
  67.  
  68. massive(const int &rowsnum,const int&columsnum){
  69. rows = rowsnum;
  70. colums = columsnum;
  71. array = new int*[rows];
  72. for(int i=0;i<rows;i++){
  73. array[i] = new int[colums];
  74. }
  75.  
  76. }
  77.  
  78. massive(const massive& obj){
  79. this->rows = obj.rows;
  80. this->colums = obj.colums;
  81. this->array = new int*[rows];
  82. for(int i=0;i<this->rows;i++){
  83. array[i] = new int[this->colums];
  84. }
  85. for(int i=0;i<this->rows;i++){
  86. for(int j=0;j<this->colums;j++){
  87. this->array[i][j] = obj.array[i][j];
  88. }
  89. }
  90. }
  91.  
  92. ~massive(){
  93. for(int i=0;i<rows;i++){
  94. delete[] array[i];
  95. }
  96. delete[] array;
  97. }
  98. friend void PrintMassive(const massive &obj);
  99. friend map<int,int> BuildNewOne(const massive&obj);
  100.  
  101. };
  102. map<int,int> BuildNewOne(const massive&obj){
  103. map<int,int> values;
  104. int k = 0;
  105. for(int i=0;i<obj.rows;i++){
  106. for(int j=0;j<obj.colums;j++){
  107. for(int t=0;t<obj.rows;t++){
  108. for(int w = 0;w<obj.colums;w++){
  109. if(obj.array[i][j]==obj.array[t][w]){
  110. k++;
  111. }
  112. }
  113. }if(k>1){
  114. values[obj.array[i][j]] = k;
  115. }
  116. k = 0;
  117. }
  118. }
  119.  
  120.  
  121.  
  122. return values;
  123. }
  124. void PrintMassive(const massive &obj){
  125. for(int i=0;i<obj.rows;i++){
  126. for(int j=0;j<obj.colums;j++){
  127. cout << obj.array[i][j] << " ";
  128. }
  129. cout << endl;
  130. }
  131. cout << "----------------------------------" << endl;
  132. }
  133.  
  134. int main(){
  135. massive a(3,4);
  136. a.FillMassive();
  137. PrintMassive(a);
  138. massive c(BuildNewOne(a));
  139. c.PrintMap();
  140.  
  141. c.FillMassiveMap();
  142. c.PrintMapMassive();
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement