AOJ Introduction to Programming Topic # 5, Topic # 6

Topic # 5

ITP1_5_A

Rectangle drawing

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

Frame drawing

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

Chessboard drawing

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

Structured programming

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('')

Topic # 6

ITP1_6_A

Inversion of sequence

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

Finding the missing card

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

Number of residents in the official residence

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

Vector and matrix product

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)

Recommended Posts

AOJ Introduction to Programming Topic # 1, Topic # 2, Topic # 3, Topic # 4
AOJ Introduction to Programming Topic # 7, Topic # 8
AOJ Introduction to Programming Topic # 5, Topic # 6
Introduction to AOJ Programming (ALDS1)-# 7 Tree Structure
An introduction to Python Programming
[Introduction to Python3 Day 1] Programming and Python
Introduction to MQTT (Introduction)
Introduction to Scrapy (1)
Introduction to Scrapy (3)
Introduction to Supervisor
Introduction to Tkinter 1: Introduction
Introduction to PyQt
Introduction to Scrapy (2)
[Linux] Introduction to Linux
Introduction to Scrapy (4)
Introduction to discord.py (2)
Introduction to discord.py
Introduction to Programming (Python) TA Tendency for beginners
Introduction to Lightning pytorch
Introduction to Web Scraping
Introduction to Nonparametric Bayes
Introduction to EV3 / MicroPython
Introduction to Python language
Introduction to TensorFlow-Image Recognition
Introduction to OpenCV (python)-(2)
Introduction to PyQt4 Part 1
Introduction to Dependency Injection
Introduction to Private Chainer
Introduction to machine learning
Introduction to electronic paper modules
A quick introduction to pytest-mock
Introduction to dictionary lookup algorithm
Introduction to Monte Carlo Method
[Learning memorandum] Introduction to vim
Introduction to PyTorch (1) Automatic differentiation
opencv-python Introduction to image processing
Introduction to Cython Writing [Notes]
An introduction to private TensorFlow
An introduction to machine learning
[Introduction to cx_Oracle] Overview of cx_Oracle
A super introduction to Linux
[Introduction to pytorch-lightning] First Lit ♬
Introduction to Anomaly Detection 1 Basics
Introduction to RDB with sqlalchemy Ⅰ
[Introduction to Systre] Fibonacci Retracement ♬
Introduction to Nonlinear Optimization (I)
Introduction to serial communication [Python]
An introduction to functional programming to improve debugging efficiency in 1 minute
Programming problem collection (Q16 to Q20)
Introduction to Deep Learning ~ Learning Rules ~
[Introduction to Python] <list> [edit: 2020/02/22]
Introduction to Python (Python version APG4b)
[Introduction to cx_Oracle] (8th) cx_Oracle 8.0 release
Introduction to discord.py (3) Using voice
An introduction to Bayesian optimization
Deep Reinforcement Learning 1 Introduction to Reinforcement Learning
Super introduction to machine learning
Introduction to Ansible Part ③'Inventory'
Series: Introduction to cx_Oracle Contents
[Introduction] How to use open3d
Introduction to Python For, While