LoginSignup
0
0

More than 3 years have passed since last update.

【Python】ABC - 091 - Two Colors Card Game

Posted at

問題

それぞれ文字列が書かれている$N$枚の青いカードと、$M$枚の赤いカードがあり、ある文字列を宣言したときに青いカードにその文字列が書かれていると枚数分1円、赤いカードにその文字列が書かれていると枚数分-1円となるとkに、最大で差し引き何円もらえるかを求める問題。

方針

青いカードに含まれている文字列でないとそもそもプラスになる可能性が存在しないので、青いカードに含まれている文字列に着目して、青いカード、赤いカードにかかれている文字列をカウントし、文字列ごとに何円もらえるのかを算出して、最大値を更新していく。

文字列にある要素が含まれているかをリストのlist.count()でカウントする。

N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]
res = 0
for s in set(S):
    score = S.count(s) - T.count(s)
    if score > res:
        res = score
print(res)
0
0
0

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
0
0