Algorithm/Problems

99클럽 코테 스터디 8일차 TIL + 문자열

공부좀하시졍 2025. 4. 9. 23:30

https://www.acmicpc.net/problem/9996

# 9996 한국이 그리울 땐 서버에 접속하지

import sys
input = sys.stdin.readline

n = int(input())
pattern = input().split('*')
start = pattern[0]
end = pattern[1]

for _ in range(n):
    name = input()

    if len(name) >= (len(start)+len(end)) and name.startswith(start) and name.endswith(end):
        print("DA")
    else:
        print("NE")
  • 패턴은 *을 기준으로 시작해야하는 문자와 끝나야하는 문자로 주어진다.
  • 시작하는 패턴과 끝나는 패턴을 split함수를 이용해 나누어준다.
  • 주어진 파일 이름이 패턴의 길이보다 길어야 조건을 충족할 수 있기 때문에
    • 패턴의 길이보다 길고 
    • startswith() 와 endswith() 함수를 이용해 패턴을 충족하다면 DA 출력
    • 그렇지 않으면 NE 출력