본문 바로가기

Algorithm/Implementation

(C++) - 백준(BOJ) 9286 : Gradabase

반응형

https://www.acmicpc.net/problem/9286

 

9286번: Gradabase

For each case, output the line “Case x:” where x is the case number, on a single line, followed by a list of integers, each on a new line, between 1 and 6. If the student has graduated from the school, do not print them.

www.acmicpc.net

구현 문제였습니다.

📕 풀이방법

📔 입력 및 초기화

테스트 케이스 개수 t와 각 테스트 케이스의 학생 수 num을 선언해줍니다. 이후에 적절히 입력해줍니다.

📔 풀이과정

학생들의 서순대로 입력을 받을 때마다 6학년 미만이라면 내년에 학교를 졸업하는 것이 아니기 때문에 vector v에 그 학생의 다음 학년을 push해줍니다.

📔 정답출력

출력형식에 맞게 출력해줍니다.


📕 Code

#include <bits/stdc++.h>
using namespace std;
int t, num;
vector <int> v;

int main(){
    cin >> t;
    for(int i = 1; i <= t; i++){
        v.clear();
        cin >> num;
        for(int j = 0, x; j < num; j++){
            cin >> x;
            if(x < 6) v.push_back(x + 1);
        }
        printf("Case %d:\n", i);
        for(auto d : v) cout << d << '\n';
    }
}

'Algorithm > Implementation' 카테고리의 다른 글

(C++) - 백준(BOJ) 8574 : Ratownik  (0) 2022.02.17
(C++) - 백준(BOJ) 8725 : Szachy  (0) 2022.02.16
(C++) - 백준(BOJ) 9063 : 대지  (0) 2022.02.14
(C++) - 백준(BOJ) 8716 : Pole  (0) 2022.02.10
(C++) - 백준(BOJ) 1408 : 24  (0) 2022.02.09