Python Algorithms - Greedy - "Card Game"

Sunmi Shin·2022년 11월 5일

Python Algorithms

목록 보기
4/7
post-thumbnail

Problme:
Pick a card which has the greatest number.
가장 높은 숫자가 쓰인 카드를 뽑아라.

Rules:
1. The arrangement of cards are N rows X M columns.
2. Pick a row.
3. Select the lowest card number in the row.
4. What you will finally choose is the greatest number among cards, considering that you get the lowest card number in every row.

Solution:
Find the lowest number in every row, and then pick the greatest number among them.

#Get how many rows and how many columns there are.(n X m)
n, m = map(int, input().split())

#Initialize the result.
result = 0

#In the for-loop, get the input cards, 
#and compare the minimum number of input cards with the result. 
#The result will be reset if it finds smaller numbers.
for _ in range(n):
    cards = list(map(int, input().split()))
    if result < min(cards):
        result = min(cards)
    else: pass
    
print(result)
profile
Tempest Data Analyst

0개의 댓글