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

A - 正直者 x, y = map(int, input().split()) if (x >= y): print(x) else: print(y) メモ map関数を使うことでも、1行の標準入力を複数の変数に代入できる。

記事を読む

[Python] ABC018 B

問題 B - 文字列の反転 回答 S = input() N = int(input()) LR = ans = S for lr in LR: left = lr - 1 right = lr - 1 ans = ans + ...

記事を読む

[Python] ABC001 C

C - 風力観測 deg, dis =(int(x) for x in input().split()) direction = '' w = -1 lst_wind_direction =['NNE','NE','ENE', 'E','ESE','SE','SSE',...

記事を読む

[Python] Punctuationの一括削除

punctuationとは、記号文字列のことです。 str.translate() を使う方法と、正規表現を使う方法で行ってみます。 str.translate() を使うPunctuationの削除 str.translate()を使い、Punctuat...

記事を読む

[Python] ABC014 A

問題 A - けんしょう先生のお菓子配り 回答 a = int(input()) b = int(input()) remainder = a % b shortage = 0 if remainder > 0: shortage = b - ...

記事を読む


Public Domain YottaGin No Rights Reserved.