diff --git a/stack_problems/the_celebrity_problem.cpp b/stack_problems/the_celebrity_problem.cpp new file mode 100644 index 0000000..0cf718b --- /dev/null +++ b/stack_problems/the_celebrity_problem.cpp @@ -0,0 +1,66 @@ +//Problem-You are in a party of N people, where only one person is known to everyone. +//Such a person may be present in the party, if yes, (s)he doesn’t know anyone in the party. +//Your task is to find the stranger (celebrity) in party. +//You will be given a square matrix M[][] where if an element of row i and column j is +//set to 1 it means ith person knows jth person. +//You need to complete the function getId() which finds the id of the celebrity +//if present else return -1. The function getId() +//takes two arguments, the square matrix M and its size N. + +//SOLUTION +#include +using namespace std; +#define MAX 501 +int getId(int M[MAX][MAX],int n); +int main() +{ + int T; + cin>>T; + int M[MAX][MAX]; + while(T--) + { + int N; + cin>>N; + memset(M,0,sizeof M); + for(int i=0;i>M[i][j]; + } + } + cout<s; + for(int i=0;i1){ + int A=s.top(); + s.pop(); + int B=s.top(); + s.pop(); + if(M[A][B]==1){ + s.push(B); + } + else{ + s.push(A); + } + } + int C=s.top(); + s.pop(); + for(int i=0;i