본문 바로가기
python-algorithm

백준 8892 팰린드롬

by 무적김두칠 2023. 11. 29.

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

 

8892번: 팰린드롬

팰린드롬은 어느 방향으로 읽어도 항상 같은 방법으로 읽을 수 있는 단어이다. 예를 들어, civic, radar, rotor, madam은 팰린드롬이다. 상근이는 단어 k개 적혀있는 공책을 발견했다. 공책의 단어는 ICPC

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from itertools import permutations
 
 
def check(s):
    if (s[0+ s[1]) == (s[0+ s[1])[::-1]:
        return s[0+ s[1]
    else:
        return False
 
 
def solution(s_list):
    s_per = list(permutations(s_list, 2))
    for i in s_per:
        if check(i):
            return check(i)
 
    return 0
 
 
if __name__ == '__main__':
    t = int(input())
    for j in range(t):
        n = int(input())
        s_list = [input() for i in range(n)]
        print(solution(s_list))
 
cs

브루트포스 방식으로 모든 경우의 수를 확인하는 방법입니다~

반응형

'python-algorithm' 카테고리의 다른 글

백준 30868 개표  (0) 2023.12.04
백준 5949 Adding Commas  (1) 2023.11.29
백준 10448 유레카 이론  (0) 2023.11.28
백준 18141 Are They All Integers?  (0) 2023.11.28
백준 15122 Forbidden Zero  (0) 2023.11.28

댓글