Spread the word.

Share the link on social media.

Share
  • Facebook
Have an account? Sign In Now

Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

SIKSHAPATH

SIKSHAPATH Navigation

  • Home
  • Questions
  • Blog
    • Computer Science(CSE)
    • NPTEL
    • Startup
  • Shop
    • Internshala Answers
Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • Questions
  • Blog
    • Computer Science(CSE)
    • NPTEL
    • Startup
  • Shop
    • Internshala Answers
Home/ Questions/Q 1234
Next
In Process

SIKSHAPATH Latest Questions

Berlin
  • 0
  • 0
Berlin
Asked: October 27, 20212021-10-27T12:20:09+05:30 2021-10-27T12:20:09+05:30In: Programming Language

ChefWatson uses Social Network

  • 0
  • 0

Chef Watson uses a social network called ChefBook, which has a new feed consisting of posts by his friends. Each post can be characterized by f – the identifier of the friend who created the post, p – the popularity of the post(which is pre-calculated by ChefBook platform using some machine learning algorithm) and s – the contents of the post which is a string of lower and uppercase English alphabets.

Also, Chef has some friends, which he has marked as special.

The algorithm used by ChefBook for determining the order of posts in news feed is as follows:

  • Posts of special friends should be shown first, irrespective of popularity. Among all such posts the popular ones should be shown earlier.
  • Among all other posts, popular posts should be shown earlier.

Given, a list of identifiers of Chef’s special friends and a list of posts, you have to implement this algorithm for engineers of ChefBook and output the correct ordering of posts in the new feed.

Input

First line contains N, number of special friends of Chef and M, the number of posts. Next line contains N integers A1, A2, …, AN denoting the identifiers of special friends of Chef. Each of the next M lines contains a pair of integers and a string denoting f, p and s, identifier of the friend who created the post, the popularity of the post and the contents of the post, respectively. It is guaranteed that no two posts have same popularity, but the same friend might make multiple posts.

 

Sample Input 1 

2 4
1 2
1 1 WhoDoesntLoveChefBook
2 2 WinterIsComing
3 10 TheseViolentDelightsHaveViolentEnds
4 3 ComeAtTheKingBestNotMiss

Sample Output 1 

WinterIsComing
WhoDoesntLoveChefBook
TheseViolentDelightsHaveViolentEnds
ComeAtTheKingBestNotMiss
codechef
  • 1 1 Answer
  • 823 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    1 Answer

    • Voted
    • Oldest
    • Recent
    1. Professor
      Professor
      2021-10-27T12:38:14+05:30Added an answer on October 27, 2021 at 12:38 pm

      //C language answer

      #include<stdio.h>
      struct post{
      int f;
      int p;
      char p_str[105];
      };
      int place(struct post *pst,struct post temp_post,int p,int q){
      int end = q,j,start=0;
      while(p<=q){
      if(temp_post.p < pst[(p+q)/2].p){
      p=(p+q)/2 + 1;
      }
      else{
      q=(p+q)/2 – 1;
      }
      }

      for(j=end;j>=p && j>0;j–){
      pst[j]=pst[j-1];
      }

      pst[p]=temp_post;
      return end+1;
      }
      void display(struct post *posts , int p,int q){
      int i;
      for(i=p;i<q;i++){
      printf(“%s\n”,posts[i].p_str);
      }
      }
      main(){
      struct post splist[1000],plist[1000];
      int n,m,sp[1000],temp,i,j,s=0,e=0;
      scanf(“%d %d”,&n,&m);
      for(i=0;i<n;i++){
      scanf(“%d”,&temp);
      sp[temp]=1;
      }
      for(j=0;j<m;j++){
      struct post temp_post;
      scanf(“%d %d %s”,&temp_post.f,&temp_post.p,&temp_post.p_str);
      if(sp[temp_post.f]==1)
      s=place(splist,temp_post,0,s);
      else
      e=place(plist,temp_post,0,e);
      }
      display(splist,0,s);
      display(plist,0,e);
      }

        • 0
      • Reply
      • Share
        Share
        • Share on WhatsApp
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    Sidebar

    store ads

    Stats

    • Questions 1k
    • Answers 1k
    • Posts 149
    • Best Answers 89
    • This Free AI Tool Translates Entire Books in Minute !
    • AI News: 🎬 Hollywood’s AI Studios, 🎓 OpenAI’s Latest Gift to Educators, 🚚 Class8 Bags $22M, 🧠 Google Gemini’s Memory Upgrade
    • AI NEWS: Legal Action Against OpenAI, $16M Paid, & Elon Musk’s Praise from Investor 🤖💰📑 | AI Boosts Cloud Seeding for Water Security 🌱💧
    • AI News: 🎬AI Video Tool Scam Exposed🤯, 🛰️ AI-Powered Drones to Ukraine 😱, Google’s $20M AI Push, Sam Altman Joins SF’s Leadership Team
    • AI News: 🤝 Biden Meets Xi on AI Talks, 💡 Xavier Niel’s Advice for Europe, ♻️ Hong Kong’s Smart Bin Revolution, 🚀 AI x Huawei

    Explore

    • Recent Questions
    • Questions For You
    • Answers With Time
    • Most Visited
    • New Questions
    • Recent Questions With Time

    Footer

    SIKSHAPATH

    Helpful Links

    • Contact
    • Disclaimer
    • Privacy Policy Notice
    • TERMS OF USE
    • FAQs
    • Refund/Cancellation Policy
    • Delivery Policy for Sikshapath

    Follow Us

    © 2021-24 Sikshapath. All Rights Reserved

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.