작성일 :

문제 링크

24923번 - Canadians, eh?

설명

문장이 eh?로 끝나는지 확인해 캐나다 사람인지 판정하는 문제입니다.


접근법

문자열의 마지막 세 글자가 eh?와 정확히 일치하는지 확인합니다. 대소문자를 구분하므로 소문자 eh?일 때만 Canadian!을 출력하고, 그렇지 않으면 Imposter!를 출력합니다.


Code

C#

1
2
3
4
5
6
7
8
9
10
11
using System;

class Program {
  static void Main() {
    var s = Console.ReadLine()!;
    if (s.Length >= 3 && s.EndsWith("eh?"))
      Console.WriteLine("Canadian!");
    else
      Console.WriteLine("Imposter!");
  }
}

C++

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

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

  string s; getline(cin, s);

  if (s.size() >= 3 && s.substr(s.size() - 3) == "eh?") cout << "Canadian!\n";
  else cout << "Imposter!\n";

  return 0;
}