AOJ プログラミング入門 トピック#5, トピック#6

#トピック#5
##[ITP1_5_A](https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/5/ITP1_5_A)
###長方形の描画

```Python:Python
def Square(H, W):
    for i in range(0, H):
        for j in range(0, W):
            print("#", end='')
            
        print('')

while True:
    H, W = list(map(int, input().split()))
    
    if H == 0 and W == 0:
        break
    else:
        Square(H, W)
        print('')
```

##[ITP1_5_B](https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/5/ITP1_5_B)
###フレームの描画

```Python:Python
def Square(H, W):
    for i in range(0, H):
        for j in range(0, W):
            if i==0 or i==H-1 or j==0 or j==W-1:
                print("#", end='')
            else:
                print(".", end='')
            
        print('')

while True:
    H, W = list(map(int, input().split()))
    
    if H == 0 and W == 0:
        break
    else:
        Square(H, W)
        print('')
```

##[ITP1_5_C](https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/5/ITP1_5_C)
###チェスボードの描画

```Python:Python
def Square(H, W):
    for i in range(0, H):
        for j in range(0, W):
            if (i+j)%2==0:
                print("#", end='')
            else:
                print(".", end='')

        print('')

while True:
    H, W = list(map(int, input().split()))
    
    if H == 0 and W == 0:
        break
    else:
        Square(H, W)
        print('')
```

##[ITP1_5_D](https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/5/ITP1_5_D)
###構造化プログラミング

```Python:Python
n = int(input())

for i in range(1, n+1):
    x = i
    if x%3==0:
        print(f" {i}", end='')
    else:
        while x>0:
            if x%10==3:
                print(f" {i}", end='')
                break
            else:
                x = x // 10
print('')
```

#トピック#6
##[ITP1_6_A](https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/6/ITP1_6_A)
###数列の反転

```Python:Python
n = int(input())
A = list(map(int, input().split()))

for i in reversed(range(0, n)):
    if i==0:
        print(f"{A[i]}")
    else:
        print(f"{A[i]} ", end='')
```

##[ITP1_6_B](https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/6/ITP1_6_B)
###不足しているカードの発見

```Python:Python
card = [[False for i in range(13)] for j in range(4)]
pattern = ['S', 'H', 'C', 'D']

n = int(input())
for i in range(0, n):
    m, h = list(map(str, input().split()))
    card[pattern.index(m)][int(h)-1] = True

for i in range(0, 4):   
    for j in range(0, 13):
        if card[i][j]==False:
            print(f"{pattern[i]} {j+1}")
```

##[ITP1_6_C](https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/6/ITP1_6_C)
###公舎の入居者数

```Python:Python
card = [[False for i in range(13)] for j in range(4)]
pattern = ['S', 'H', 'C', 'D']

floor = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

n = int(input())
for i in range(0, n):
    b, f, r, v = list(map(int, input().split()))
    floor[b-1][f-1][r-1] += v
    
for b in range(0, 4):
    for f in range(0, 3):
        for r in range(0, 10):
            if r==9:
                print(f" {floor[b][f][r]}")
            else:
                print(f" {floor[b][f][r]}", end='')
    if b<3:
        print(f"####################")
```

##[ITP1_6_D](https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/6/ITP1_6_D)
###ベクトルと行列の積

```Python:Python
n, m = list(map(int, input().split()))

A = [[0 for i in range(m)] for j in range(n)]
B = [0 for i in range(m)]

for i in range(0, n):
    a = list(map(int, input().split()))
    
    for j in range(m):
        A[i][j] = a[j]

for i in range(0, m):
    b = int(input())
    B[i] = b
    
for i in range(0, n):
    ans = 0
    for j in range(0, m):
        ans += A[i][j] * B[j]
    print(ans)
```