[PYTHON] AOJ Introduction à la programmation Sujet n ° 5, Sujet n ° 6

Thème n ° 5

ITP1_5_A

Dessinez un rectangle

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

Dessiner un cadre

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

Dessiner un échiquier

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

Programmation structurée

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

Thème n ° 6

ITP1_6_A

Inversion de la séquence de nombres

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

Trouver la carte manquante

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

Nombre d'habitants du bâtiment public

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

Produit de vecteur et matrice

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 à la programmation Sujet 1, Sujet 2, Sujet 3, Sujet 4
AOJ Introduction à la programmation Sujet n ° 7, Sujet n ° 8
AOJ Introduction à la programmation Sujet n ° 5, Sujet n ° 6
Une introduction à la programmation Python
[Introduction à Python3 Jour 1] Programmation et Python
Introduction à MQTT (Introduction)
Introduction à Scrapy (1)
Introduction à Scrapy (3)
Premiers pas avec Supervisor
Introduction à Tkinter 1: Introduction
Introduction à PyQt
Introduction à Scrapy (2)
[Linux] Introduction à Linux
Introduction à Scrapy (4)
Introduction à discord.py (2)
Introduction à la programmation (Python) TA Tendency pour les débutants
Introduction à Lightning Pytorch
Premiers pas avec le Web Scraping
Introduction aux baies non paramétriques
Introduction à EV3 / MicroPython
Introduction au langage Python
Introduction à la reconnaissance d'image TensorFlow
Introduction à OpenCV (python) - (2)
Introduction à PyQt4 Partie 1
Introduction à l'injection de dépendances
Introduction à Private Chainer
Introduction à l'apprentissage automatique
Introduction au module de papier électronique
Introduction à l'algorithme de recherche de dictionnaire
Introduction à la méthode Monte Carlo
[Mémorandum d'apprentissage] Introduction à vim
Introduction à PyTorch (1) Différenciation automatique
opencv-python Introduction au traitement d'image
Introduction à l'écriture de Cython [Notes]
Introduction à Private TensorFlow
Une introduction à l'apprentissage automatique
[Introduction à cx_Oracle] Présentation de cx_Oracle
Une super introduction à Linux
Introduction à la détection des anomalies 1 principes de base
Introduction à RDB avec sqlalchemy Ⅰ
[Introduction au système] Retracement de Fibonacci ♬
Introduction à l'optimisation non linéaire (I)
Introduction à la communication série [Python]
Une introduction à la programmation fonctionnelle pour améliorer l'efficacité du débogage en 1 minute
Collecte des problèmes de programmation (Q16 à Q20)
Introduction au Deep Learning ~ Règles d'apprentissage ~
[Introduction à Python] <liste> [modifier le 22/02/2020]
Introduction à Python (version Python APG4b)
[Introduction à cx_Oracle] (8e) version de cx_Oracle 8.0
Introduction à discord.py (3) Utilisation de la voix
Introduction à l'optimisation bayésienne
Apprentissage par renforcement profond 1 Introduction au renforcement de l'apprentissage
Super introduction à l'apprentissage automatique
Introduction à Ansible Part «Inventaire»
Série: Introduction à cx_Oracle Contents
[Introduction] Comment utiliser open3d
Introduction à Python pour, pendant