0
0

AtCoder初心者 DailyTrainingメモ 2023/11/2

Last updated at Posted at 2023-11-02

参考URL

pythonでの順列全探索
https://qiita.com/wihan23/items/107dfff1ecada60845b1

ABC225 A-問題

問題文
英小文字のみからなる長さ3の文字列Sが与えられます。
Sの各文字を並び替えて得られる文字列は、何種類ありますか?

ポイント
・順列全探索は、itertools を使う
・set で重複を削除する

順列全探索
225A.py
# 順列全探索は、「itertools」をインポートする
import itertools

# 入力
S = str(input())

# 順列全探索結果をset に格納して重複を削除
ST = set(itertools.permutations(S))

# set の要素数が答え
print(len(ST))
シンプルな場合分けの解答
225A_2.py
# リストに入力
L = list(input())

# setに格納して文字数を確認する
st = set(L)

# 文字の種類別に何通りかを場合分けする
if len(st) == 1:
    ans = 1
elif len(st) == 2:
    ans = 3
elif len(st) == 3:
    ans = 6

print(ans)
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