작성일 :

문제 링크

31775번 - 글로벌 포닉스

설명

세 문자열이 순서와 관계없이 각각 l, k, p로 시작하면 GLOBAL, 아니면 PONIX를 출력하는 문제입니다.


접근법

각 문자열의 첫 글자를 확인해 l, k, p가 모두 한 번씩 등장하는지 확인합니다. 세 글자가 모두 있으면 GLOBAL, 하나라도 없으면 PONIX를 출력합니다.


Code

C#

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

class Program {
  static void Main() {
    var a = Console.ReadLine()!;
    var b = Console.ReadLine()!;
    var c = Console.ReadLine()!;

    var hasL = a[0] == 'l' || b[0] == 'l' || c[0] == 'l';
    var hasK = a[0] == 'k' || b[0] == 'k' || c[0] == 'k';
    var hasP = a[0] == 'p' || b[0] == 'p' || c[0] == 'p';

    Console.WriteLine(hasL && hasK && hasP ? "GLOBAL" : "PONIX");
  }
}

C++

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

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

  string a, b, c; cin >> a >> b >> c;

  bool hasL = (a[0] == 'l') || (b[0] == 'l') || (c[0] == 'l');
  bool hasK = (a[0] == 'k') || (b[0] == 'k') || (c[0] == 'k');
  bool hasP = (a[0] == 'p') || (b[0] == 'p') || (c[0] == 'p');

  cout << (hasL && hasK && hasP ? "GLOBAL" : "PONIX") << "\n";

  return 0;
}