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] コマンドプロンプトでtermcolorが文字化けする時

windows10のコマンドプロンプトでpythonのtermcolorで出力に色をつけようとすると、色ではなく文字化けが発生します。 termcolor は unix で使われる ANSIエスケープシーケンスというものを使うためで、これが windows のコマンドプ...

記事を読む

[Python] ABC010 A

問題 A - ハンドルネーム 回答 S = input() new_name = S + 'pp' print(new_name)

記事を読む

[Python] ABC005 A

問題 A - おいしいたこ焼きの作り方 回答 割り算するだけ。 import sys # input処理を高速化する input = sys.stdin.readline def main(): X, Y = list(map(int, inp...

記事を読む

[Python] ABC015 D DP 100点

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

記事を読む

[Python] ABC012 D ワーシャルフロイド

問題 D - バスと避けられない運命 ワーシャルフロイド ワーシャル–フロイド法(英: Warshall–Floyd Algorithm)は、重み付き有向グラフの全ペアの最短経路問題を多項式時間で解くアルゴリズムである。 出典: フリー百科事典『ウィキペデ...

記事を読む


Public Domain YottaGin No Rights Reserved.