LoginSignup
0
0

More than 1 year has passed since last update.

【AtCoder】ABC207のA,B,C問題を解く

Posted at

PythonでABC207のA,B,C問題を解く

ABC222のA,B,C問題をPython3で解答しています。
簡単な解説はコードの中に記載しています。

SNSでの発信も少しずつ始めました。フォローしていただけたらフォロー返してます。。!
Twitter

A - Four Digits

python
# 文字列として受け取り、足りない桁文を足す。
n = input()
length = len(n)
if length == 4:
    print(n)
elif length == 3:
    print('0'+n)
elif length == 2:
    print('00' + n)
elif length == 1:
    print('000'+n)


B - Failing Grade

python
# P 点未満の学生をカウントしていく
n, p = map(int, input().split())
l_a = list(map(int, input().split()))
ans = 0
for i in range(n):
    if l_a[i] < p:
        ans+= 1
print(ans)


C - Swiss-System Tournament

python

# 入力
n, m = map(int, input().split())
jan = []
for i in range(2*n):
    x = input()
    jan.append(x)
d = []
for i in range(1, 2*n+1):
    tmp = [i, 0]
    d.append(tmp)

# 各ラウンド
for i in range(m):
    # i ラウンド目の各試合の組み合わせは、i−1 ラウンド目終了時点の順位が 2k−1 位の人と 2k 位の人で試合をする
    for j in range(1, 2 * n + 1, 2):
        # i ラウンド目までの勝数が多い方が上位
        if jan[d[j][0]-1][i] == 'G' and jan[d[j-1][0]-1][i] == 'C' or jan[d[j][0]-1][i] == 'C' and jan[d[j-1][0]-1][i] == 'P' or jan[d[j][0]-1][i] == 'P' and jan[d[j-1][0]-1][i] == 'G':
            d[j][1]+= 1
        elif jan[d[j][0]-1][i] == 'G' and jan[d[j-1][0]-1][i] == 'P' or jan[d[j][0]-1][i] == 'C' and jan[d[j-1][0]-1][i] == 'G' or jan[d[j][0]-1][i] == 'P' and jan[d[j-1][0]-1][i] == 'C':
            d[j-1][1]+=1
        # i ラウンド目までの勝数が同じときは、番号が小さい方が上位
        d = sorted(d, reverse=False, key=lambda x: x[0])
        # i ラウンド目までの勝数が同じときは、番号が小さい方が上位
        d = sorted(d, reverse=True, key=lambda x: x[1])

# i ラウンド目までの勝数が同じときは、番号が小さい方が上位
d= sorted(d, reverse=False, key=lambda x: x[0])
# i ラウンド目までの勝数が同じときは、番号が小さい方が上位
d= sorted(d, reverse=True, key=lambda x: x[1])

for i in range(2*n):
    print(d[i][0])

プログラミング絶賛学習中です。
プログラミング学習中の皆様、よろしくお願いいたします。。!
Twitter

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0