1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include<iostream>
#define dim 5
using namespace std;
bool alreadyhere (int a[],int x,int pos)
{ for (int i=0;i<pos;i++)
{if (a[i]==x)
{return true;
}
}
return false;
}
int findimention (int m[dim][dim], int r)
{int d=0;
int cont =0;
for (int i=0;i<dim;i++)
{for (int j=0;j<dim;j++)
{cont=0;
for (int a=0;a<dim;a++)
{for (int b=0;b<dim;b++)
{if (m[i][j]==m[a][b])
{cont ++;
}
}
}
if (cont==r)
{d++;
}
}
}
return d/r;
}
int* repeated (int m[dim][dim], int r)
{int* k=new int[findimention(m,2)];
int count=0;
int pos=0;
for (int i=0;i<dim;i++)
{for (int j=0;j<dim;j++)
{count =0;
for (int a=0;a<dim;a++)
{for (int b=0;b<dim;b++)
{if(m[i][j]==m[a][b])
{count ++;
}
}
}
if (count == r && alreadyhere(k ,m[i][j], pos) == false)
{k[pos]=m[i][j];
pos++;
}
}
}
return k;
}
void stamp (int* v, int z)
{for (int i=0;i<z;i++)
{cout<<"\nElement"<<i+1<<"--->"<<v[i];
}
}
int main ()
{int a[][dim]= {{13,13,14,22,8},{3,17,9,21,16},{33,27,44,51,17},{8,1,-3,22,4},{2,0,17,-9,-3}};
cout<<"Function REPEATED\n\n\nInsert number of repetitions--->";
int rep;
cin>>rep;
stamp ( repeated(a,rep),findimention(a,rep));
system ("Pause");
return 0;
}
|