problem link:
Discuss: in this problem you have to check weather a element less then zero or mat[i][j] and mat[n-1-i][n-1-j] is not equal. if this happen then this matrix is non symmetric else it is symmetric matrix
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n,i,j,flag,t,k;
cin >>t;
for(k=1;k<=t;k++)
{
long long mat[101][101];
flag=0;
char str[10];
cin >>str>>str>>n;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin >>mat[i][j];
if(mat[i][j]<0)
flag=1;
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(mat[i][j]!=mat[n-1-i][n-1-j])
{
flag=1;
break;
}
}
}
cout <<"Test #"<<k<<':';
if(flag)
cout <<" Non-symmetric."<<endl;
else
cout <<" Symmetric."<<endl;
}
return 0;
}
Discuss: in this problem you have to check weather a element less then zero or mat[i][j] and mat[n-1-i][n-1-j] is not equal. if this happen then this matrix is non symmetric else it is symmetric matrix
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n,i,j,flag,t,k;
cin >>t;
for(k=1;k<=t;k++)
{
long long mat[101][101];
flag=0;
char str[10];
cin >>str>>str>>n;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin >>mat[i][j];
if(mat[i][j]<0)
flag=1;
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(mat[i][j]!=mat[n-1-i][n-1-j])
{
flag=1;
break;
}
}
}
cout <<"Test #"<<k<<':';
if(flag)
cout <<" Non-symmetric."<<endl;
else
cout <<" Symmetric."<<endl;
}
return 0;
}
No comments:
Post a Comment