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 Beginner ContestをPythonで取り組んだ振り返り(ABC452 A,B)

0
Posted at

どうもこんにちは!

今週もBまでの2完でした。
C問題は文字列の長さごとに、何文字目ごとに含まれる文字をまとめた辞書を作ろうとしたんですが、その辞典でTLEになってしまい問題を解くどころではありませんでした。。
しばらく取り組んでいないうちにいろんなことを忘れて完全になまりました。

問題と公式の解説のリンク

問題は以下のリンクから。

A - Gothec -

問題

与えられた月日が五節句(1/7, 3/3, 5/5, 7/7, 9/9)に含まれるかを判定する問題。

考え方とコード

受け取った月日をif文で判定。

m,d = map(int,input().split())
print("Yes" if (m == 1 and d == 7) or (m == d and m in (3,5,7,9)) else "No")

B - Draw Frame -

問題

h×Wのマスがあり、1マスごとに'#'か'.'にするとします。このマスの上下左右の端を'#',それ以外を'.'とするとしたときのマス目を出力する問題。

考え方とコード

マスの初期値を'#'とし、2重ループで特定のマス(i,j)を塗るとしたときに、iとjが両方とも端でないときに'.'に書き換える形をとりました。

h,w = map(int,input().split())
ans = []
for _ in range(h):
    tmp = ['#'] * w
    ans.append(tmp)

for i in range(h):
    for j in range(w):
        if 0 < i < h-1 and 0 < j < w-1:
            ans[i][j] = '.'

for i in range(h):
    print("".join(ans[i]))

ではでは。

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?