알고리즘 공부 11일차

김서영·2024년 1월 9일
0

알고리즘

목록 보기
11/25

1. 백준 - 삼각형과 세 변

while True:
    a, b, c = list(map(int, input().split()))
    if a == b == c == 0:
        break
    elif a == b == c:
        print("Equilateral")
    elif max(a, b, c) >= a + b + c - max(a, b, c): # 가장 긴 변이 나머지 변 더한 값보다 길거나 같은지
        print("Invalid")
    elif (a == b) or (a == c) or (b == c):
        print("Isosceles")
    else:
        print("Scalene")
        
    # if문 순서도 중요했다!!

2. 백준 - 가희와 키워드

# 백준 22233 가희와 키워드
import sys
sys.stdin = open('input.txt', 'r')

N, M = map(int, sys.stdin.readline().split())
keyword = {sys.stdin.readline().rstrip() : 0 for _ in range(N)}
answer = N
for i in range(M):
    essay = list(sys.stdin.readline().rstrip().split(","))
    for j in essay:
        if j in keyword.keys():
            if keyword[j] == 0:
                answer -= 1
                keyword[j] = 1
    print(answer)

3. 백준 - 카드 2

# 백준 2164 카드2
from collections import deque

N = int(input())
lst = deque(range(1, N+1))

while len(lst) != 1:
    lst.popleft()
    a = lst.popleft()
    lst.append(a)
    
print(*lst)

4. 프로그래머스 - 카펫

def solution(brown, yellow):
    answer = []
    sol = brown - 4 # 테두리 빼주고
    n1 = 1 # 세로길이 - 2를 1부터 시작
    while True:
        n2 = (sol - 2*n1) // 2 # 가로길이 - 2의 길이
        if n1*n2 != yellow: # (가로 - 2) * (세로 - 2)값이 yellow와 같아야 함
            n1 += 1
        else:
            answer = [max(n1, n2)+2, min(n1, n2)+2]
            break
    return answer
profile
개발과 지식의 성장을 즐기는 개발자

0개의 댓글