4
3

はじめに

paiza様のpython問題集から、単語のカウント問題を解きました

問題

スペースで区切られた英単語列が与えられます。
英単語列に含まれる英単語の出現回数を出現した順番に出力してください。

実装したソースコード

array1 = input().split(' ')
array2 = []
for x in array1:
    if x not in array2:
        array2.append(x)

for y in array2:
    count = 0
    for z in array1:
        if z == y:
            count += 1 
    print(y + " " + str(count))

実行した結果

test1.jpg

最後に

この問題は実は段階別にヒント問題を解いて最終的にこの問題を解く流れです。

4
3
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
4
3