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?

ABC394をPythonで(A~D)

Posted at

鹿島建設プログラミングコンテスト2025(AtCoder Beginner Contest 394)の解答等の速報的まとめ

A問題

2の個数の分だけ2を繋げて出力する

A
print("2"*input().count("2"))

B問題

長さ順でソートして繋げる

B
print(*sorted([input()for _ in[0]*int(input())],key=len),sep="")

C問題

後ろから順にWAをACに置換する

C
s = list(input())
for i in range(len(s) - 2, -1, -1):
    if s[i] + s[i + 1] == "WA":
        s[i], s[i + 1] = "A", "C"

print(*s, sep="")

D問題

スタックを使ってペアができるか調べる

D
s = list(input())

stack = []
for s_i in s:
    if stack and stack[-1] + s_i in {"()", "[]", "<>"}:
        stack.pop()
    else:
        stack.append(s_i)

print("No" if stack else "Yes")
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?