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] デコレーターについて

Python のデコレーターについて理解するための個人的なまとめです。 デコレーター 8.6. 関数定義 @f1(arg) @f2 def func(): pass は大体次と等価です。 def func(): pass func = f1(arg...

記事を読む

[Python] アメリカ株の情報取得

株の分析をしてみたくなったのでまとめていきます。 情報の取得が簡単に行えるアメリカ株を対象にします。 モジュール numpy scipy pandas matplotlib は使うとして、他に下記の2つのモジュールを使っていきます。 yfinance ...

記事を読む

[Python] ABC004

B - 回転 table = [] while True: try: table.append(list(input().split())) except: break table = table #print(table) table_180...

記事を読む

[Python] 連結リストを逆順にする

Python で連結リストを逆順にします。 連結リストは以下の実装を使います。 単純に考えれば、空の連結リストを用意して値を先頭から挿入していくことで、逆順の連結リストを取得できます。 def reverse_linked_list(sel...

記事を読む

[Python] ABC015 D DP 100点

問題 D – 高橋くんの苦悩 回答 動的計画法を使います。 Python では TLE ですが、PyPy では間に合いました。 W = int(input()) N, K = map(int, input().split()) AB =...

記事を読む


Public Domain YottaGin No Rights Reserved.