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?

ペアの数値の入った表を罫線入りで出力 (paizaランク C 相当)

Posted at

今回の問題はこれ
https://paiza.jp/works/mondai/stdout_primer/stdout_primer__specific_format_step4

自然数 H, W, A, B が与えられるので
ヨコW行、縦H行の(A,B)を " | " で区切ることという問題。

2 3 7 8なら

(7, 8) | (7, 8) | (7, 8)
========================
(7, 8) | (7, 8) | (7, 8)

というふうに出力する

まずは1行目を出力してみる

Arr = input().split()
H = int(Arr[0])
W = int(Arr[1])
A = int(Arr[2])
B = int(Arr[3]) 

for i in range(1,W+1):
    if i != W:
        print(f"({A}, {B})",end=" | ")
    else:
        print(f"({A}, {B})")

次にH行分出力

Arr = input().split()
H = int(Arr[0])
W = int(Arr[1])
A = int(Arr[2])
B = int(Arr[3]) 

for j in range(1,H+1):
    for i in range(1,W+1):
        if i != W:
            print(f"({A}, {B})",end=" | ")
        else:
            print(f"({A}, {B})")

次に縦の罫線を引く方法だが九九と同じ考え方で
(A, B) = 6文字(間は,と半スペで2文字)
|  =3文字
あわせて9文字
それをW-1分繰り返し、最後は(A, B)だけなので6文字だから
count = 9 * (W -1) + 6
これを=でかければOK

Arr = input().split()
H = int(Arr[0])
W = int(Arr[1])
A = int(Arr[2])
B = int(Arr[3]) 

for j in range(1,H+1):
    for i in range(1,W+1):
        if i != W:
            print(f"({A}, {B})",end=" | ")
        else:
            print(f"({A}, {B})")
    if j < H:
        count = 9 * (W -1) + 6
        print(f"{'='*count}")

一発合格でした。

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?