EX16 - 英単語テスト対策 Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

説明ページに戻る


問題文

明日、英語の単語テストがあります。出題される可能性のある単語は S_1, S_2, \dots, S_NN 個です。
長い単語が好きであるあなたは、これらの単語のうち K 文字以上の単語を勉強することにしました。
S_1, S_2, \dots, S_N から K 文字以上 の単語を取り出し、順序を変えず空白区切りで 1 行に出力してください。

注意: この問題は for 文のみで正答することが可能です。しかし本節は内包表記の節ですので、極力内包表記を使った回答を考えてみてください。

制約

  • 1 \le N \le 20
  • 1 \le K \le 16
  • S_i\ (1 \le i \le N) は英小文字からなる長さ 1 以上 15 以下の文字列である。

入力

入力は以下の形式で標準入力から与えられる。

N K
S_1 S_2 \cdots S_N

出力

S_1, S_2, \dots, S_N から K 文字以上 の単語を取り出し、順序を変えず空白区切りで 1 行に出力せよ。
ただし、K 文字以上の単語が 1 個もない場合は、空行を出力せよ。


入力例 1

8 6
apple is solution dog hospital tree success cat

出力例 1

solution hospital success

apple, is, solution, dog, hospital, tree, success, cat のうち、6 文字以上の単語は solution, hospital, success3 個です。


入力例 2

10 5
study pen computer car table bus education phone veil aide

出力例 2

study computer table education phone

入力例 3

5 10
selection island advice training trial

出力例 3



テスト入出力

書いたプログラムがACにならず、原因がどうしてもわからないときだけ見てください。

クリックでテスト入出力を見る

テスト入力1

1 1
a

テスト出力1

a

テスト入力2

20 16
appearance relationship instruction proof recommendation analysis development accommodation requirement transportation announcement assistance difference understanding identification freedom population aspect conference environment

テスト出力2



テスト入力3

20 13
responsibility advertisement achievement determination embarrassment opportunity explanation imagination information independence consideration application introduction organization presentation communication appreciation cooperation observation   preparation

テスト出力3

responsibility advertisement determination embarrassment consideration communication

解答例

必ず自分で問題に挑戦してみてから見てください。

クリックで解答例を見る
# 入力
N, K = map(int, input().split())
S = input().split()

# K文字以上の単語を抽出
result = [word for word in S if len(word) >= K]

# 空白区切りで出力
print(*result)