Hackerrank Angry Professor Solutions

A Discrete Mathematics professor has a class of students. Frustrated with their lack of discipline, the professor
decides to cancel class if fewer than some number of students are present when class starts. Arrival times go
from on time (arrivalTime 0) to arrived late (arrivalTime > 0).
Given the arrival time of each student and a threshhold number of attendees, determine if the class is
cancelled.

Python

def angryProfessor(k, a):
students = 0
for i in a:
if i <= 0: students += 1
if students < k: print("YES")
else: print("NO")
angryProfessor(3,[-1,-3,4,2])
def angryProfessor(k, a):
    students = 0
    for i in a:
        if i <= 0: students += 1
    if students < k: print("YES")
    else: print("NO")

angryProfessor(3,[-1,-3,4,2])
def angryProfessor(k, a): students = 0 for i in a: if i <= 0: students += 1 if students < k: print("YES") else: print("NO") angryProfessor(3,[-1,-3,4,2])

Enter fullscreen mode Exit fullscreen mode

JavaScript

function angryProfessor(k, a) {
let students = 0;
for (let i = 0; i < a.length; i++) {
if (a[i] <= 0) {
students++;
}
}
if (students < k) {
console.log("YES");
} else {
console.log("NO");
}
}
function angryProfessor(k, a) {
  let students = 0;
  for (let i = 0; i < a.length; i++) {
    if (a[i] <= 0) {
      students++;
    }
  }
  if (students < k) {
    console.log("YES");
  } else {
    console.log("NO");
  }
}
function angryProfessor(k, a) { let students = 0; for (let i = 0; i < a.length; i++) { if (a[i] <= 0) { students++; } } if (students < k) { console.log("YES"); } else { console.log("NO"); } }

Enter fullscreen mode Exit fullscreen mode

C++

#include <iostream>
using namespace std;
void angryProfessor(int k, int a[], int n) {
int students = 0;
for (int i = 0; i < n; i++) {
if (a[i] <= 0) {
students++;
}
}
if (students < k) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
#include <iostream>
using namespace std;

void angryProfessor(int k, int a[], int n) {
  int students = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] <= 0) {
      students++;
    }
  }
  if (students < k) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
#include <iostream> using namespace std; void angryProfessor(int k, int a[], int n) { int students = 0; for (int i = 0; i < n; i++) { if (a[i] <= 0) { students++; } } if (students < k) { cout << "YES" << endl; } else { cout << "NO" << endl; } }

Enter fullscreen mode Exit fullscreen mode

原文链接:Hackerrank Angry Professor Solutions

© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享
To do the useful thing, to say the courageous thing, to contemplate the beautiful thing: that’s enough for one man’s life.
做有用的事,说勇敢的话,想美好的事,一生足矣
评论 抢沙发

请登录后发表评论

    暂无评论内容