#include <fstream>
using namespace std;
ifstream fin("matrice.in");
ofstream fout("matrice.out");
int main()
{
int n,m,A[101][101];
fin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
fin>>A[i][j];
//cerinta a: elementul maxim din matrice
int max=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(A[i][j]>max) max=A[i][j];
fout<<max<<endl;
//cerinta b: pe cate linii se afla maximul
int c=0;
for(int i=1;i<=n;i++)
{
int gasit=0;
for(int j=1;j<=m;j++)
if(A[i][j]==max) gasit=1;
if(gasit==1) c++;
}
fout<<c<<endl;
//cerinta c: afisare linii cu elementele in ordine strict crescatoare
for(int i=1;i<=n;i++)
{
int ok=1;
for(int j=1;j<m;j++)
if(A[i][j]>=A[i][j+1]) ok=0;
if(ok)
{
for(int j=1;j<=m;j++)
fout<<A[i][j]<<" ";
fout<<endl;
}
}
//cerinta d: elementele care sunt unice pe coloana lor
//cu vector de frecventa
for(int j=1;j<=m;j++)
{
int F[1001]={0};
for(int i=1;i<=n;i++)
F[A[i][j]]++;
for(int v=0;v<=1000;v++)
if(F[v]==1) fout<<v<<" ";
}
fout<<endl;
//cu numarare aparitii
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
int x=0;
for(int k=1;k<=n;k++)
if(A[i][j]==A[k][j]) x++;
if(x==1) fout<<A[i][j]<<" ";
}
fout<<endl;
//cu verificare ca e unic prin reducere la absurd
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
int ok=1;
for(int k=1;k<=n;k++)
if(i!=k && A[i][j]==A[k][j]) ok=0;
if(ok==1) fout<<A[i][j]<<" ";
}
fout<<endl;
//cerinta e: stergerea liniei de la mijlocul matricii
for(int i=n/2+1;i<n;i++)
for(int j=1;j<=m;j++)
A[i][j]=A[i+1][j];
n--;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
fout<<A[i][j]<<" ";
fout<<endl;
}
return 0;
}
|