0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AtCoderをPythonで取り組んだ振り返り(ABC399 A,B)

Posted at

どうもこんにちは!

今週もAtCoderのコンテストに参加できたので、記録がてら振り返ります。
今回はBまで完答。Cはグラフに関する問題で、手が出せず。森という概念を初めて聞いた気がしました。

問題

問題は以下のリンクから。取り組めたA,Bを振り返ります。

A - Hamming Distance -

同じ長さの文字列が2つ与えられるので、n文字目が異なる個数を回答する問題。シンプルに1文字ずつ比較して数えました。

n = int(input())
s = input()
t = input()
ans = 0
for i in range(n):
  if s[i] != t[i]:
    ans += 1

print(ans)

B - Ranking with Ties -

n人分の試験の点数が与えられるので、その順位付けをするという問題。同じ点数の場合は同順位として、次はその人数を飛ばした順位になります。例えば1位が2人いたら、その次の点数の人は3位となる感じです。

n = int(input())
s = [int(x) for x in input().split()]
ans = [0] * n
r = 1
#print(ans)

while r < n+1:
  k,m = 0,0
  for i in range(n):
      if ans[i] == 0:
          m = max(m,s[i])
#  print(m)
  k = s.count(m)
  for i in range(n):
    if s[i] == m:
      ans[i] = r
  r += k

for i in ans:
    print(i)

おわりに

今回はグラフの勉強不足につきます。4月になるので目標は未達、問題を解けるように、落ち着いて1つずつ勉強を進めたいと思います。

ではでは。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?