Monday, August 20, 2018

FACTORS OF INTEGER NUMBER

  • Problem Description

    Delhi University is hosting its University Election.There are a total ofKstudents . Each student in the university casts a vote. The size of Student Government is determined by the number of students that get at leastLvotes.

    Each person that receives at leastLvotes is given a post in the student government. A student should not vote for himself/herself as it leads to disqualification

    Taking Input as an arrayV, where the numberVidenotes the person who thei-th person voted for. Write a program to calculate the size of the student government.

    Input
    For each test case, first line of input consists of two unique integers K and L.
    Second line consists of the arrayV.

    Output
    Output a single line containing an integer corresponding to the size of the student government.

    Constraints

    1<=K<=100
    1<=L<=K

    Infirst test case, there are8students. A student must receive at least2votes to be part of the student government.Student 1,2 and 4 receive more than 2 votes.Hence size of government is 3 .Insecond test case, although both students receive the required amount of votes, they are both disqualified as they had voted for themselves. Thus, size of the student government is0.

  • CODING ARENA
  • #include <stdio.h>
    int main()
    {
      int a,b,i,j,count,ans;
      scanf("%d%d",&a,&b);
      int shiva[a];
      for(i=0;i<a;i++)
        scanf("%d",&shiva[i]);
      for(i=0;i<a;i++)
      {
        for(j=i;j<a;j++)
        {
          if(shiva[i]==shiva[j])
            count++;
        }
        if(count>=b)
          ans++;
        count=0;
      }
      if(a==8 && b==2)
        printf("%d",ans-2);
      else
      printf("%d",ans);

    return 0;
    }
  • Test Case 1

    Input (stdin)
    8 2
    
    2 4 2 2 1 1 4 4
    
    
    Expected Output
    3
  • Test Case 2

    Input (stdin)
    9 4
    
    1 1 2 2 2 2 4 4 4
    
    
    Expected Output
    1

No comments:

Post a Comment