첫번째 코드
회문을 만드는 함수를 작성한 이후에
조건 3개가 모두 충족되는 경우 YES, 그 중에서 하나라도 맞지 않으면 NO를 출력하도록 하자!
여기서 포인트는?
회문을 만드는 함수!!! + 인덱스 주의!!
test_case = int(input())
for tc in range(test_case):
s = str(input())[: -1]
n = len(s)
def palindrome(text):
for i in range(len(text)//2):
if text[i] != text[(-1)-i]:
return False
return True
cond1 = palindrome(s)
end_index = int((n-1)/2)
cond2 = palindrome(s[ : end_index])
start_index = int(((n-1)/2)*(-1))
cond3 = palindrome(s[start_index : ])
if cond1 & cond2 & cond3 :
print(f'#{tc+1} YES')
else:
print(f'#{tc+1} NO')
맞는데? 오류?
이상하다 왜 swea와 로컬 결과가 다르지...?
두번째 코드
아무리 생각해도 이상하다... 왜 뭐가 문제지..?
심지어 로컬에서는 문제 없이 돌아가는데, swea내에 output의 결과가 다르다...
엥 뭐지..
이유를 알기 위해 중간중간 print문을 사용해가면서 어디서 문제가 발생하는지 찾아냈다.
여기는 input에 \n이 나오지 않는 문자열이라서 입력 자체가 달랐던 것이다...
test_case = int(input())
for tc in range(test_case):
s = str(input())
n = len(s)
def palindrome(text):
for i in range(len(text)//2):
if text[i] != text[(-1)-i]:
return False
return True
cond1 = palindrome(s)
end_index = int((n-1)/2)
cond2 = palindrome(s[ : end_index])
start_index = int(((n-1)/2)*(-1))
cond3 = palindrome(s[start_index : ])
if cond1 & cond2 & cond3 :
print(f'#{tc+1} YES')
else:
print(f'#{tc+1} NO')
통과
링크