YottaGin

Freedom is a responsible choice.

[Python] ABC007 B

2019/11/3 2019/11/3 アルゴリズム, プログラミング

問題

B – 辞書式順序

入力例/出力例と同じ値になるようにしてみる。

組み込み関数の chr(i) と ord(c) を使う。

回答

A = input()
lst_a = list(A)

if len(lst_a) >=2:
    print(''.join(lst_a[:-1]))
elif lst_a[0] == 'a':
    print('-1')
else:
    print(chr(ord(lst_a[0])-1))

Atcoder, Python GinO

関連記事

[Python] 2分ヒープ (1)

2分ヒープ 2分ヒープを理解して、Pythonで実装します。 まず、heap とは、「積み重なった山のようなもの」です。a heap of stones と言えば、石が山のように積み重なっているものです。 ヒープソートは、この山のように積み重なったものの一番上...

記事を読む

[Python] 配列を逆順にする

与えられた配列を逆順にする In-place アルゴリズムを Python で書いてみます。 通常は list.reverse() や list を使います。 考え方は簡単で、左右両端にインデックスを置いて入れ替え、その後一つ狭めてさらに左右両端を入れ替える…と...

記事を読む

[Python] ABC019 D

問題 D - 高橋くんと木の直径 回答 20点回答 全て探索します。 AtCoder Beginner Contest 019 解説 from AtCoder Inc. import sys N = int(input())...

記事を読む

[Python] ABC002 B

B - 罠 W = input() output = '' for w in W: if w not in 'aiueo': output += w print(output) メモ pythonでは、in を使うと、その文字が含まれる...

記事を読む

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

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

記事を読む


Public Domain YottaGin No Rights Reserved.