1
0

More than 3 years have passed since last update.

python3 多重ループ(記録)

Posted at

多重ループ

Cの配列の中からsの中で該当するものを判定する。
今回はforの中にforがあることと、inで文字列を確認することがポイント。

m = int(input())

#[""]文字列の配列を作成するため
c = [""]*m

for i in range(m):
    c[i] = input()  

n = int(input())

s = [""]*n

for l in range(n):
    s[l] = input()

for i in range(m):
    for l in range(n):
        if c[i] in s[l]:
            print("YES")
        else:
            print("NO")

入力例2
2
c
d
2
cat
dog

出力例2
YES
NO
NO

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0