작성일 :

문제 링크

10384번 - 팬그램

설명

입력으로 주어진 문자열이 팬그램(Pangram)인지, 또는 더블 팬그램(Double pangram), 트리플 팬그램(Triple pangram)인지 판별하는 문제입니다.


각 알파벳이 등장하는 횟수에 따라 아래와 같이 분류합니다:

  • 모든 알파벳이 한 번 이상 등장 → "Pangram!"
  • 모든 알파벳이 두 번 이상 등장 → "Double pangram!!"
  • 모든 알파벳이 세 번 이상 등장 → "Triple pangram!!!"
  • 이 외의 경우는 "Not a pangram"


접근법

  • 각 테스트케이스마다 알파벳의 등장 횟수를 세기 위해 크기 26의 배열을 선언합니다.
  • 대소문자 구분 없이 알파벳만 필터링하여 소문자로 변환한 뒤, 등장 횟수를 누적합니다.
  • 누적된 횟수 중 가장 적게 등장한 알파벳의 개수를 기준으로 판별합니다.
  • 결과는 "Case i: " 형식으로 출력하며, 테스트케이스 번호를 함께 표시합니다.


Code

C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using System;
using System.Linq;

class Program {
  static void Main() {
    int t = int.Parse(Console.ReadLine());

    for (int i = 1; i <= t; i++) {
      var line = Console.ReadLine();
      var freq = new int[26];

      foreach (char c in line) {
        if (char.IsLetter(c))
          freq[char.ToLower(c) - 'a']++;
      }

      int minCount = freq.Min();

      string result = minCount switch {
        0 => "Not a pangram",
        1 => "Pangram!",
        2 => "Double pangram!!",
        _ => "Triple pangram!!!"
      };

      Console.WriteLine($"Case {i}: {result}");
    }
  }
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <bits/stdc++.h>

using namespace std;

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

  string s; getline(cin, s);
  int t = stoi(s);

  for (int i = 1; i <= t; i++) {
    getline(cin, s);
    int cnt[26] = {0, };

    for (char c : s)
      if (isalpha(c)) cnt[tolower(c) - 'a']++;

    int minCnt = 4;
    for (int x : cnt)
      minCnt = min(minCnt, x);

    string ans;
    if (minCnt == 0) ans = "Not a pangram";
    else if (minCnt == 1) ans = "Pangram!";
    else if (minCnt == 2) ans = "Double pangram!!";
    else ans = "Triple pangram!!!";

    cout << "Case " << i << ": " << ans << "\n";
  }

  return 0;
}