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?

More than 1 year has passed since last update.

paizaラーニング 例外処理のタブーサーチ 【備忘録】

Posted at

自分用メモです。
問題:例外処理のタブーサーチ (paizaランク B 相当)
https://paiza.jp/works/mondai/steinsgate/restore_command_boss

最初に書いたコード

firsttry.py
n, m, l = map(int, input().split())
d = [[int(x) for x in input().split()] for y in range(n)]
p = [[int(x) for x in input().split()] for y in range(l)]

dif = []
for i in range(l-1):
    difl = []
    for j in range(m):
        difl.append(p[i+1][j]-p[i][j])
    dif.append(difl)
    
for difi in dif:
    for i, di in enumerate(d):
        if difi == di:
            print(i+1)

difl配列を作らずに差分を求められそう

修正版

secondtry.py
n, m, l = map(int, input().split())
d = [[int(x) for x in input().split()] for y in range(n)]
p = [[int(x) for x in input().split()] for y in range(l)]

dif = [[p[i+1][j] - p[i][j] for j in range(m)] for i in range(l-1)]
  
for difi in dif:
    for i, di in enumerate(d):
        if difi == di:
            print(i+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?