작성일 :

문제 링크

31518번 - Triple Sevens

설명

각 휠에 주어진 숫자 집합이 모두 7을 포함하면 777, 하나라도 없으면 0을 출력하는 문제입니다.


접근법

입력으로 주어진 세 줄을 순회하며 각 줄에 7이 있는지 확인합니다. 세 줄 모두에 7이 있으면 777, 아니면 0을 출력합니다.


Code

C#

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

class Program {
  static void Main() {
    var n = int.Parse(Console.ReadLine()!);
    var ok = true;
    for (var i = 0; i < 3; i++) {
      var parts = Console.ReadLine()!.Split();
      var found = false;
      for (var j = 0; j < n; j++) {
        if (parts[j] == "7") {
          found = true;
          break;
        }
      }
      if (!found) ok = false;
    }

    Console.WriteLine(ok ? "777" : "0");
  }
}

C++

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

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

  int n; cin >> n;
  bool ok = true;
  for (int i = 0; i < 3; i++) {
    bool found = false;
    for (int j = 0; j < n; j++) {
      int x; cin >> x;
      if (x == 7) found = true;
    }
    if (!found) ok = false;
  }

  cout << (ok ? 777 : 0) << "\n";

  return 0;
}