21-1 行列两次结构体排序
#include<iostream>
#include<algorithm>
using namespace std;
const int N=11;
int n,m;
int k=0;
int a[N][N];
struct pointx
{
int idx;
int x,y;
bool operator< (const pointx & t)const
{
return idx>t.idx;
}
}px[N];
struct pointy
{
int idy;
int xx,yy;
bool operator< (const pointy & tt)const
{
return idy<tt.idy;
}
}py[N];
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
px[k].idx=a[i][j];
px[k].x=i,px[k].y=j;
k++;
}
for(int l=0,r=m;r<m*m;l+=m,r+=m)
{
sort(px+l,px+r);
int maxx=px[l].y;
int h=0;
for(int i=1;i<=n;i++)
{
py[h].idy=a[i][maxx];
py[h].xx=i,py[h].yy=maxx;
h++;
}
sort(py,py+h);
if(py[0].idy==px[l].idx)
cout<<" "<<px[l].x<<" "<<px[l].y<<" "<<px[l].idx<<endl;
}
return 0;
}
3 4
1 2 3 5
1 2 3 4
1 2 3 4
---------------------------
2 4 4
3 4 4