Sunday, 3 September 2017

Find New Friends in Social Network




Input:
3
Mani 3 ram raj guna
Ram 2 kumar Kishore
Mughil 3 praveen Naveen Ramesh

Output:
Raj guna kumar Kishore praveen Naveen Ramesh

#include<stdio.h>

#include<string.h>
#define N 10
struct Node{
 char name[20];
 char list[N][20];
 int no;
}friends[N];

void findFriend(int n)
{
    int i,j,k,count,m;
    for(i=0;i<n;i++)
    {
        m = friends[i].no;
      for(j=0;j<m;j++)
      {
             for(k=count=0;k<n;k++)
             {
                if( strcmpi(friends[i].list[j],friends[k].name) != 0)
                 {
                  count++;
                 }
            }
           if(count==n)
          printf("%s ",friends[i].list[j]);
       }
    }
 }

int main()
{
int t,n,i,j;
clrscr();
scanf("%d",&t);
       for(i=0;i<t;i++)
      {
           scanf(" %s",friends[i].name);
           scanf(" %d",&n);
          friends[i].no = n;
         for(j=0;j<n;j++)
         {
            scanf(" %s",friends[i].list[j]);
          }
      }
  findFriend(t);
getch();
}

No comments:

Post a Comment