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] ABC015 A

問題 A - 高橋くんの研修 回答 A = input() B = input() if len(A) > len (B): print(A) else: print(B)

記事を読む

[Python] requests/beautifulsoup でスクレイピング

requests/beautifulsoup/lxml のコンビでスクレイピングを行ってみます。 Requests Requests: HTTP for Humans™ Python で一番使いやすいHTMLライブライです。 下記コマンドで...

記事を読む

[Python] pandasで条件に合う行を削除

何度かググっているので、自分用にメモしておきます。 pandasで条件に合う行を削除したい時は、「列Aにnを持つ行を削除する」ではなく、「列Aにn以外の値を持つ行を抽出して、新しいdataframeを作る」と考えた方が楽に操作できます。 以下の操作を行います。 ...

記事を読む

[Python] multiprocessingを試す (4)

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

記事を読む

[Python] Kadane’s algorithm

最大部分配列問題 数値で構成された配列内の部分配列の中で、総和が最大となるものを求めます。 Incomputer science, themaximum sum subarray problemis the task of finding a contig...

記事を読む


Public Domain YottaGin No Rights Reserved.