작성일 :

문제 링크

20336번 - Haughty Cuisine

설명

여러 세트 메뉴 중 하나를 골라 그 구성 그대로 추천 목록을 출력하는 문제입니다.


접근법

아무 세트 메뉴 하나를 그대로 출력하면 됩니다. 첫 번째 메뉴를 읽어 저장한 뒤, 나머지는 입력만 소비합니다. 저장한 메뉴의 개수와 항목을 그대로 출력합니다.


Code

C#

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

class Program {
  static void Main() {
    var n = int.Parse(Console.ReadLine()!);
    var first = new List<string>();

    for (var i = 0; i < n; i++) {
      var parts = Console.ReadLine()!.Split();
      var d = int.Parse(parts[0]);
      if (i == 0) {
        for (var j = 0; j < d; j++)
          first.Add(parts[j + 1]);
      }
    }

    Console.WriteLine(first.Count);
    foreach (var item in first)
      Console.WriteLine(item);
  }
}

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
#include <bits/stdc++.h>
using namespace std;

typedef vector<string> vs;

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

  int n; cin >> n;
  int d; cin >> d;
  vs first(d);
  for (int i = 0; i < d; i++)
    cin >> first[i];

  for (int i = 1; i < n; i++) {
    cin >> d;
    for (int j = 0; j < d; j++) {
      string tmp; cin >> tmp;
    }
  }

  cout << first.size() << "\n";
  for (const auto& item : first)
    cout << item << "\n";

  return 0;
}