https://www.acmicpc.net/problem/1254
코드
s = input()
def is_palindrome(string):
for i in range(len(string)//2):
if string[i] != string[len(string)-1-i]:
return False
return True
for i in range(len(s)):
new_s = s+(s[:i])[::-1]
if is_palindrome(new_s):
print(len(new_s))
break
주어진 문자열 S의 앞에서부터 1글자, 2글자,... 이렇게 떼어서 거꾸로 S 뒤에 붙여보며 팰린드롬인지 확인한다.
'문제풀이 > 완전탐색' 카테고리의 다른 글
[Python/파이썬] SW Expert Academy 20731번 서로소 그리드 (1) | 2024.06.12 |
---|---|
[Python/파이썬] 백준 21943번 연산 최대로 (0) | 2024.06.03 |
[Python/파이썬] 백준 14889번 스타트와 링크 (0) | 2024.05.30 |
[Python/파이썬] 백준 28075번 스파이 (0) | 2024.03.15 |
[Python/파이썬] 백준 2503번 숫자 야구 (0) | 2024.02.09 |
https://www.acmicpc.net/problem/1254
코드
s = input() def is_palindrome(string): for i in range(len(string)//2): if string[i] != string[len(string)-1-i]: return False return True for i in range(len(s)): new_s = s+(s[:i])[::-1] if is_palindrome(new_s): print(len(new_s)) break
주어진 문자열 S의 앞에서부터 1글자, 2글자,... 이렇게 떼어서 거꾸로 S 뒤에 붙여보며 팰린드롬인지 확인한다.
'문제풀이 > 완전탐색' 카테고리의 다른 글
[Python/파이썬] SW Expert Academy 20731번 서로소 그리드 (1) | 2024.06.12 |
---|---|
[Python/파이썬] 백준 21943번 연산 최대로 (0) | 2024.06.03 |
[Python/파이썬] 백준 14889번 스타트와 링크 (0) | 2024.05.30 |
[Python/파이썬] 백준 28075번 스파이 (0) | 2024.03.15 |
[Python/파이썬] 백준 2503번 숫자 야구 (0) | 2024.02.09 |