작성일 :

문제 링크

16017번 - Telemarketer or not?

설명

네 자리 전화번호가 텔레마케터 번호인지 판별하는 문제입니다.


접근법

1번째와 4번째 숫자가 8 또는 9이고, 2번째와 3번째 숫자가 같으면 텔레마케터 번호입니다.

조건을 만족하면 ignore, 아니면 answer를 출력합니다.



Code

C#

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

class Program {
  static void Main() {
    var d = new int[4];
    for (var i = 0; i < 4; i++)
      d[i] = int.Parse(Console.ReadLine()!);
    bool ok = (d[0] == 8 || d[0] == 9) && (d[3] == 8 || d[3] == 9) && (d[1] == d[2]);
    Console.WriteLine(ok ? "ignore" : "answer");
  }
}

C++

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

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

  int d[4];
  for (int i = 0; i < 4; i++)
    cin >> d[i];
  bool ok = (d[0] == 8 || d[0] == 9) && (d[3] == 8 || d[3] == 9) && (d[1] == d[2]);
  cout << (ok ? "ignore" : "answer") << "\n";

  return 0;
}