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

関連記事

condaコマンド

windows、Anaconda Command Prompt上でanacondaを使う際のcondaコマンドについて、備忘録的にまとめます。 公式コマンドレファレンス Command reference ライブラリ一覧 インストールしたライブラリ一覧を...

記事を読む

[Python] ABC004

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

記事を読む

[Python] ABC014 A

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

記事を読む

[Python] ABC013 A

問題 A - A 回答  ord で Unicode コードポイント に変換して引き算します。 X = input() ans = ord(X) - ord('A') + 1 print(ans) 辞書で対応表を作成します。 X = inp...

記事を読む

[Python] ダイクストラ法

Python で、ダイクストラ法を使って、重み付きの有向グラフの単一始点最短経路問題を解きます。 以下の続きです。 ダイクストラ法 ダイクストラ法(だいくすとらほう、英: Dijkstra's algorithm)はグラフ理論における辺の重みが...

記事を読む


Public Domain YottaGin No Rights Reserved.