본문 바로가기

programming/algorithm 공부

[Algorithm] Angry Professor




> Quest.

A Discrete Mathematics professor has a class of  students. Frustrated with their lack of discipline, he decides to cancel class if fewer than  students are present when class starts.

Given the arrival time of each student, determine if the class is canceled.



> Input.

Input Format

The first line of input contains , the number of test cases.

Each test case consists of two lines. The first line has two space-separated integers,  (students in the class) and (the cancelation threshold). The second line contains  space-separated integers () describing the arrival times for each student.

Note: Non-positive arrival times () indicate the student arrived early or on time; positive arrival times () indicate the student arrived  minutes late.



> Output.

Output Format

For each test case, print the word YES if the class is canceled or NO if it is not.



> solve

주어진 학생들의 도착시간에 따라 출력을 합니다.


#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

 int main(){
     int t; 
     scanf("%d",&t); //test times 

     for(int a0 = 0; a0 < t; a0++){ 
          int n; 
          int k; 
          int m=0;  // m -> at on time student, angry : over then k. 
          scanf("%d %d",&n,&k); //n -> students number, k -> cancelation threshold. 
          int a[n]; 
          for(int a_i = 0; a_i < n; a_i++){ 
              scanf("%d",&a[a_i]); 
              if(*(a+a_i) <= 0){ 
                    m+=1; 
              } 
          } 
          printf("%s\n", (m >= k ? "NO" : "YES")); //so, output. 
    } 
    return 0; 
 }




반응형

'programming > algorithm 공부' 카테고리의 다른 글

[Algorithm] Connecting Towns  (0) 2017.10.09
[Algorithm] Handshake / 악수  (0) 2017.10.09
[Algorithm] Divisible Sum Pairs  (0) 2017.10.09
[Algorithm] 캥거루 두 마리  (0) 2017.10.09
[Algorithm] 사과나무와 오렌지나무  (0) 2017.10.09