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] Educational DP Contest D – Knapsack 1

問題 D - Knapsack 1D - Knapsack 1 回答 最初にTLEで間に合わなかった回答 考え方としては合っているはず…。 import sys # inputを高速化する。 input = sys.stdin.readline ...

記事を読む

[Python] ABC016 C

問題 C - 友達の友達 回答 友達の友達を数える 集合を使い、友達の友達を探索して数えます。 import collections N, M = map(int, input().split()) adjacent_dict = col...

記事を読む

[データ構造] 三分探索木をPythonで実装

Python で三分探索木を実装してみます。 ノードクラス それぞれのノードは、その文字を持ち、左右と真ん中に子を持ちます。 また、キーとしてその文字列が存在する場合は、値を持ちます。 class Node(object): ...

記事を読む

[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] ABC002 D by python

D - 派閥 from itertools import combinations n, m = map(int, input().split()) matrix_relations = * n for _ in range(n)] # matrixに関係を格納する。...

記事を読む


Public Domain YottaGin No Rights Reserved.