💡문제접근
- 처음에 개의치않고 바로 접근했다가 바로 WA를 받고 신경을 써야하는 부분을 찾기 시작했다.
- 별표(*)는 빈 문자열도 포함이 된다고 조건에 나와있었다.
- 만약 패턴에서 (*)을 제외한 나머지 왼쪽/오른쪽 부분의 길이의 합이 파일의 길이보다 작으면 당연히 일치할 수 없으므로 이런 경우 "NE"를 출력하고 나머지 왼쪽/오른쪽 부분의 길이의 합이 파일의 길이와 같거나 크다면 넘어간다.
- 별표(*)의 왼쪽/오른쪽 부분의 문자열을 비교해서 성립이 가능하다면 "DA", 불가능하다면 "NE"를 출력한다.
💡코드(메모리 : 31256KB, 시간 : 44ms)
import sys
input = sys.stdin.readline
N = int(input())
Expression = list(input().strip().split("*"))
left = Expression[0].strip()
right = Expression[1].strip()
for _ in range(N):
file_name = input().strip()
if len(file_name) >= len(left) + len(right):
if left == ''.join(map(str, file_name[:len(left)])) and right == ''.join(map(str, file_name[len(file_name)-len(right):])):
print("DA")
else:
print("NE")
else:
print("NE")
💡소요시간 : 17m