📜  给每个人加分且不超过100分后通过的最大学生数

📅  最后修改于: 2021-04-29 15:27:06             🧑  作者: Mango

给定一个数组arr代表n学生们。及格成绩为50学生可以得分的最高分是100 ,任务是通过给学生加分来最大化通过考试的学生。
请注意,如果给一个学生加分,那么所有其他学生也将获得相同数量的加分,而任何学生的得分都不会超过100 。最后打印可以通过考试的学生总数。

例子:

方法:M如果是其他所有学生的最高分数,那么可以给予的最大可能的奖励分数将是100 - M 。现在,对于每个分数+(100-M)≥50的学生,增加计数。最后打印计数。

下面是上述方法的实现:

C++
// C++ Implementation of above approach. 
#include 
#include
using namespace std;
  
// Function to return the number 
// of students that can pass 
int check(int n, int marks[])
{
    // maximum marks 
    int* x = std::max_element(marks,marks+5); 
  
    // maximum bonus marks that can be given 
    int bonus = 100-(int)(*x);
    int c = 0;
    for(int i=0; i= 50)
            c += 1;
    }
    return c;
}
      
// Driver code
int main()
{
int n = 5;
int marks[] = {0, 21, 83, 45, 64}; 
cout<


Java
// Java Implementation of above approach. 
import java.util.*;
class GFG{
// Function to return the number 
// of students that can pass 
static int check(int n, List marks)
{
    // maximum marks 
    Integer x = Collections.max(marks); 
  
    // maximum bonus marks that can be given 
    int bonus = 100-x;
    int c = 0;
    for(int i=0; i= 50)
            c += 1;
    }
    return c;
}
      
// Driver code
public static void main(String[] args)
{
int n = 5;
 List marks = Arrays.asList(0, 21, 83, 45, 64); 
System.out.println(check(n, marks)); 
}
}
// This code is contributed by mits


Python3
# Python3 Implementation of above approach.
  
# Function to return the number 
# of students that can pass
def check(n, marks):
  
    # maximum marks
    x = max(marks)
  
    # maximum bonus marks that can be given
    bonus = 100-x
    c = 0
    for i in range(n):
  
        # counting the number of 
        # students that can pass
        if(marks[i] + bonus >= 50):
            c += 1
  
    return c
  
# Driver code
n = 5
marks = [0, 21, 83, 45, 64]
print(check(n, marks))


C#
// C# Implementation of above approach. 
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
class GFG{
// Function to return the number 
// of students that can pass 
static int check(int n, List marks)
{
    // maximum marks 
    int x = marks.Max(); 
  
    // maximum bonus marks that can be given 
    int bonus = 100-x;
    int c = 0;
    for(int i=0; i= 50)
            c += 1;
    }
    return c;
}
      
// Driver code
public static void Main()
{
int n = 5;
List marks = new List(new int[]{0, 21, 83, 45, 64}); 
Console.WriteLine(check(n, marks)); 
}
}
// This code is contributed by mits


PHP
= 50)
            $c += 1;
    }
    return $c;
}
      
// Driver code 
$n = 5;
$marks = array(0, 21, 83, 45, 64); 
echo check($n, $marks);


输出:
3