백준 4주차

이재윤·2022년 12월 3일
1

백준

목록 보기
4/4

#7568 덩치.

n = int(input())

physical = []

for i in range(n):
    a,b = map(int,input().split())
    physical.append([a,b])

rank = []
for i in range(n):
    rank.append(1)
    
for i in range(n):
    for j in range(n):
        if physical[i][0] < physical[j][0] and physical[i][1] < physical[j][1]:
            rank[i] += 1
for i in range(n):
    print(rank[i],end=' ')

#1065 한수.

import sys
n = int(sys.stdin.readline())
if n < 100 :
    print(n)
else :
    cnt =99
    for i in range(100,n+1):
        a = i // 100
        b = i // 10 % 10
        c = i % 10

        if (b-a) == (c-b):
            cnt +=1 
    print(cnt)

#9012 괄호.

import sys
n = int(sys.stdin.readline())
for i in range(n):
    vps = sys.stdin.readline()

    stack = 0
    for j in vps:
        if j == '(':
            stack += 1
        elif j == ')':
            stack -= 1
            if stack < 0:
                break
    if stack == 0:
        print("YES")
    else:
        print("NO")

#1620 나는야 포켓몬 마스터!!

n,m = map(int,input().split())

pokedex = dict()
for i in range(1, n+1):
    pokedex[input()] = i

for i in range(m):
    find = input()
    try:
        dex_num = int(find)
        for key in pokedex:
            if pokedex[key] == dex_num:
                print(key)
    except:
        print(pokedex[find])

→ try/except 구문과 딕셔너리 파트 복기하기 좋은 문제였다.

## 백준 제출 버전
import sys
n,m = map(int,sys.stdin.readline().split())

pokedex = dict()
for i in range(1, n+1):
    pokedex[sys.stdin.readline().strip()] = i

for i in range(m):
    find = sys.stdin.readline().strip()
    try:
        dex_num = int(find)
        for key in pokedex:
            if pokedex[key] == dex_num:
                print(key)
    except:
        print(pokedex[find])
profile
하지만 중요한 건 꺾이지 않는 마음 #코드업100제 #백준

0개의 댓글