YottaGin

Freedom is a responsible choice.

[Python] ABC004 C

2019/3/26 2019/4/17 プログラミング

C – 入れ替え

n = int(input())

n = n % 30

lst_num = ['1', '2', '3', '4', '5', '6']

for i in range(n):
    first = i % 5 + 1
    second = i % 5 +2
    lst_num[first-1], lst_num[second-1] = lst_num[second-1], lst_num[first-1]

print(int(''.join(lst_num)))

メモ

  • pythonで変数のswap(入れ替え)について考えて検討してみた

Atcoder, Python GinO

関連記事

[Python] ABC010 B

問題 B - 花占い 回答 余りを利用する n = int(input()) a = list(map(int, input().split())) count = 0 for i in range(n): for j in range(a, ...

記事を読む

[Python] ABC012 B

問題 B - 入浴時間 回答 N = int(input()) seconds = N % 60 minutes = (N // 60) % 60 hours = N // (60 ** 2) % 60 s_seconds = '{:02d}'.forma...

記事を読む

[Python] pnadasの基本的な使いかた

pandas の基本的な使い方、備忘録です。 公式 pandas: powerful Python data analysis toolkit jupyter notebook を使っている時は、メソッドにカーソルを置いて、Shift + Tab でそのメソッ...

記事を読む

[Python] multiprocessingを試す (4)

前回からの続きです。 pool python で mulitprocessing を行う方法として、process 以外に pool があります。 プロセスプール process と pool の違い Python Multiproce...

記事を読む

[Python] ABC007 D 桁DP

ABC007 Dを桁DPを使って解きます。 桁DP/Digit DP 「n以下の整数の処理」を考えるときに、 大きい桁から一桁ずつ数を見ていき、結果を代入するDP配列に、nより小さいことが確定しているかどうかのフラグを含めることで状態を管理する動的計画法で...

記事を読む


Public Domain YottaGin No Rights Reserved.