작성일 :

문제 링크

9286번 - Gradabase

설명

학생들의 학년이 주어지면 모두 한 학년씩 올리고, 6학년이었던 학생은 졸업 처리하여 출력하지 않는 문제입니다.


접근법

먼저 각 테스트케이스마다 케이스 번호를 출력합니다.

다음으로 학생들의 학년을 하나씩 읽으면서, 6학년이면 졸업이므로 건너뛰고 그 외에는 학년을 1 올려서 출력합니다.



Code

C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System;

namespace Solution {
  class Program {
    static void Main(string[] args) {
      var t = int.Parse(Console.ReadLine()!);
      for (var tc = 1; tc <= t; tc++) {
        var m = int.Parse(Console.ReadLine()!);
        Console.WriteLine($"Case {tc}:");
        for (var i = 0; i < m; i++) {
          var g = int.Parse(Console.ReadLine()!);
          if (g == 6)
            continue;
          Console.WriteLine(g + 1);
        }
      }
    }
  }
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int t; cin >> t;
  for (int tc = 1; tc <= t; tc++) {
    int m; cin >> m;
    cout << "Case " << tc << ":\n";
    for (int i = 0; i < m; i++) {
      int g; cin >> g;
      if (g == 6)
        continue;
      cout << g + 1 << "\n";
    }
  }

  return 0;
}