#include<bits/stdc++.h>
using namespace std;
bool matrix[1000][1000];
void take(int n)
{
cout << "Enter Array Element :: " << endl;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin >> matrix[i][j];
}
}
}
bool know(int a, int b)
{
return matrix[a][b];
}
int celebrity(int n)
{
int a = 0, i;
int b = n-1;
while(a < b)
{
if(know(a, b))
a++;
else
b--;
}
for(i=0;i<n;i++)
{
if((i!=a) && (know(a, i) || !know(i, a)))
return -1;
}
return a+1;
}
int main()
{
int n;
cout << "Enter Array Size :: ";
cin >> n;
take(n);
int d = celebrity(n);
if(d == -1)
cout << "No Celebrity." << endl;
else
cout << "Celebrity ID :: " << d << endl;
return 0;
}
using namespace std;
bool matrix[1000][1000];
void take(int n)
{
cout << "Enter Array Element :: " << endl;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin >> matrix[i][j];
}
}
}
bool know(int a, int b)
{
return matrix[a][b];
}
int celebrity(int n)
{
int a = 0, i;
int b = n-1;
while(a < b)
{
if(know(a, b))
a++;
else
b--;
}
for(i=0;i<n;i++)
{
if((i!=a) && (know(a, i) || !know(i, a)))
return -1;
}
return a+1;
}
int main()
{
int n;
cout << "Enter Array Size :: ";
cin >> n;
take(n);
int d = celebrity(n);
if(d == -1)
cout << "No Celebrity." << endl;
else
cout << "Celebrity ID :: " << d << endl;
return 0;
}
Comments
Post a Comment