LoginSignup
2
2

More than 5 years have passed since last update.

Pythonで競プロに挑む日誌 vol.11 ~for 文中の "_"~

Last updated at Posted at 2018-09-17

現在の目標

  • 今年の10月内に茶色を取得する
    • ABC の A, B 問題を全部解く←イマココ
  • 年内に緑色を取得する
    • ABC の C, D 問題を全部解く
  • APG4b で C++ にも手を出す

今日の問題

ABC004B - 回転
https://beta.atcoder.jp/contests/abc004/tasks/abc004_2

結果

answer1.py
#coding: utf-8
c = (input() + input() + input() + input())[::-1]
print(c[0:7])
print(c[7:14])
print(c[14:21])
print(c[21:28])

# 実行時間:17 ms
# メモリ :2940 KB
# コード長:132 Byte
# 得点  :100/100

やることはすぐにわかりました.

C_{i,j} → C_{3-i, 3-j} 

とすればよいので, 文字を連結して, 単純に逆から表示しました. ただ, やっぱりもっと短く書く方法はあるのですね.

answer2.py
#coding: utf-8
print("\n".join(input() for _ in range(4))[::-1])

# 実行時間:17 ms
# メモリ :2940 KB
# コード長:65 Byte
# 得点  :100/100

たしかに, join で改行連結すればよいですね.
あと, for を回したいけど値を使わないときは, _ で代用できるんですね.

今回学んだこと

明日やること

  • ABC を解き続ける.
2
2
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
2
2