تبلیغات
#include<iostream.h>
#include<conio.h>
int main ()
{
int i,j,k1,k2,k,d1,d2,n,a[10][10],b[10][10],d[10][10],temp,t1=0,m=0,h1,h2,h3,w1,w2,w3,p1,p2,f1,f2;
//tarif kardane 3 matris
for(i=0;i<10;i++)
for(j=0;j<10;j++)
{
a[i][j]=0;
b[i][j]=0;
d[i][j]=0;
}
cout<<"tedade satr va sotun ra vared konid\n";
cin>>d1>>d2;
cout<<"tedade anasore gheire sefr ra vared konid\n";
cin>>n;
cout<<"etala'ate zir ra vared konid\n";
for(i=0;i<n;i++)                     
{
cout<<(i+1)<<"\tomin onsor\nsatr ra vared konid\n";
cin>>f1;
cout<<"sotun ra vared konid\n";
cin>>f2;
cout<<"meghdar ra vared konid\n";
cin>>k;
a[f1][f2]=k;
}
clrscr();
cout<<"shoma matris zir ra vared kardeh e'id\n\n";
for(i=0;i<d1;i++)
{
for(j=0;j<d2;j++)
{
if(a[i][j]!=0)
{
cout<<i<<"\t\t"<<j<<"\t\t"<<a[i][j]<<"\n";
d[t1][0]=i;
d[t1][1]=j;
d[t1][2]=a[i][j];
t1++;
}
}
}
//avaz kardane satr va sotun
for(i=0;i<n;i++)
{
temp=d[m][0];
d[m][0]=d[m][1];
d[m][1]=temp;
m++;
}
cout<<"\n";
cout<<"matris taranahade ke hanooz moratab nashode\n";
for(i=0;i<n;i++)
{
cout<<"\n";
for(j=0;j<3;j++)
{
cout<<d[i][j]<<"\t";
}
}
cout<<"\nanswer is\n";
p1=0;
p2=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{//agar meghdare satr az satre badi kuchektar bashd
if(d[p2][p1]<d[j][p1])
{
 h1=d[p2][p1];
 h2=d[p2][1];
 h3=d[p2][2];
 w1=d[j][0];
 w2=d[j][1];
 w3=d[j][2];
 d[p2][0]=w1;
 d[p2][1]=w2;
 d[p2][2]=w3;
 d[j][0]=h1;
 d[j][1]=h2;
 d[j][2]=h3;
}
}
p2++;
}
p2=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{//agar maghdare satr barabare satre badi bashad
if(d[p2][p1]==d[j][p1])
{
k1=d[p2][p1+1];
k2=d[j][p1+1];
if(k1<k2)
{
 h1=d[p2][p1];
 h2=d[p2][1];
 h3=d[p2][2];
 w1=d[j][0];
 w2=d[j][1];
 w3=d[j][2];
 d[p2][0]=w1;
 d[p2][1]=w2;
 d[p2][2]=w3;
 d[j][0]=h1;
 d[j][1]=h2;
 d[j][2]=h3;
 }
}
}
p2++;
}
for(i=0;i<n;i++)
{
cout<<"\n";
for(j=0;j<3;j++)
{
cout<<d[i][j]<<"\t";
}
}

getch();
return 0;
}