Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <map>
- #include <iostream>
- #include <iomanip>
- using namespace std;
- class massive{
- private:
- int **array;
- int rows,colums;
- map<int,int> values;
- public:
- massive(const int&q){
- rows = colums = q;
- array = new int*[q];
- for(int i=0;i<q;i++){
- array[i] = new int[q];
- }
- }
- void FillMassive(){
- srand(time(NULL));
- for(int i=0;i<this->rows;i++){
- for(int j=0;j<this->colums;j++){
- this->array[i][j] = rand()%10 + 1;
- }
- }
- }
- void PrintMap(){
- for(const auto&q:values){
- cout << q.first << " : " << q.second << endl;
- }
- cout << "---------------------------------------" << endl;
- }
- void PrintMapMassive(){
- int i=0;
- for(const auto&q:values){
- for(int j=0;j<q.second;j++){
- cout << array[i][j] << " ";
- }
- cout << endl;
- i++;
- }
- cout << "---------------------" << endl;
- }
- void FillMassiveMap(){
- int i=0;
- for(const auto&q:values){
- for(int j=0;j<q.second;j++){
- array[i][j] = q.first;
- }
- i++;
- }
- }
- massive(const map<int,int>&values1){
- values = values1;
- array = new int*[values.size()];
- int i=0;
- for(const auto&a:values){
- array[i] = new int[a.second];
- i++;
- }
- }
- massive(const int &rowsnum,const int&columsnum){
- rows = rowsnum;
- colums = columsnum;
- array = new int*[rows];
- for(int i=0;i<rows;i++){
- array[i] = new int[colums];
- }
- }
- massive(const massive& obj){
- this->rows = obj.rows;
- this->colums = obj.colums;
- this->array = new int*[rows];
- for(int i=0;i<this->rows;i++){
- array[i] = new int[this->colums];
- }
- for(int i=0;i<this->rows;i++){
- for(int j=0;j<this->colums;j++){
- this->array[i][j] = obj.array[i][j];
- }
- }
- }
- ~massive(){
- for(int i=0;i<rows;i++){
- delete[] array[i];
- }
- delete[] array;
- }
- friend void PrintMassive(const massive &obj);
- friend map<int,int> BuildNewOne(const massive&obj);
- };
- map<int,int> BuildNewOne(const massive&obj){
- map<int,int> values;
- int k = 0;
- for(int i=0;i<obj.rows;i++){
- for(int j=0;j<obj.colums;j++){
- for(int t=0;t<obj.rows;t++){
- for(int w = 0;w<obj.colums;w++){
- if(obj.array[i][j]==obj.array[t][w]){
- k++;
- }
- }
- }if(k>1){
- values[obj.array[i][j]] = k;
- }
- k = 0;
- }
- }
- return values;
- }
- void PrintMassive(const massive &obj){
- for(int i=0;i<obj.rows;i++){
- for(int j=0;j<obj.colums;j++){
- cout << obj.array[i][j] << " ";
- }
- cout << endl;
- }
- cout << "----------------------------------" << endl;
- }
- int main(){
- massive a(3,4);
- a.FillMassive();
- PrintMassive(a);
- massive c(BuildNewOne(a));
- c.PrintMap();
- c.FillMassiveMap();
- c.PrintMapMassive();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement