300x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 27 | 28 |
Tags
- PYTHON
- CSS
- 그래프
- 코딩 테스트
- 코딩
- 브루트포스
- 킥스타트
- nlp
- 코딩테스트
- 운영체제
- 프로그래머스
- 순열
- 백준
- linux
- kick start
- 동적 프로그래밍
- DFS
- 구글 킥스타트
- BFS
- 알고리즘
- 동적프로그래밍
- 딥러닝
- 프로그래밍
- google coding competition
- dp
- OS
- 리눅스
- 네트워크
- 파이썬
- AI
Archives
- Today
- Total
오뚝이개발자
[Google Kick Start] 2022 구글 킥스타트 Round B Palindromic Factors 풀이 본문
코딩 테스트/Google Kick Start
[Google Kick Start] 2022 구글 킥스타트 Round B Palindromic Factors 풀이
땅어 2022. 4. 24. 14:59728x90
300x250
문제
https://codingcompetitions.withgoogle.com/kickstart/round/00000000008caa74/0000000000acee89
Kick Start - Google’s Coding Competitions
Hone your coding skills with algorithmic puzzles meant for students and those new to coding competitions. Participate in one round or join them all.
codingcompetitions.withgoogle.com
나의 풀이
1. 약수를 구하는 함수 findFactors()를 만든다.
2. 팰린드롬인지를 판별하는 isPalindrome() 함수를 만든다.
약수를 구하기 위해선 1~int(sqrt(A))+1 만큼의 범위 동안 나누어 떨어지는 수를 찾으면 된다. 중복되는 경우가 생길 수 있으니 set에 저장한다.(예컨대, 25의 경우 5*5이므로 5가 중복으로 카운트 된다.)
팰린드롬을 판별하기 위해선 길이가 짝수, 홀수인 경우로 나누어 주면 된다.
코드
# https://codingcompetitions.withgoogle.com/kickstart/round/00000000008caa74/0000000000acee89
import math
def findFactors(a):
factor_set = set()
for i in range(1, int(math.sqrt(a))+1):
if a % i == 0:
factor_set.add(i)
factor_set.add(a//i)
return factor_set
def isPalindrome(s):
if len(s)==1:
return True
if len(s) % 2 == 0:
left = s[:len(s)//2]
right = s[len(s)//2:]
elif len(s) % 2 == 1:
left = s[:len(s)//2]
right = s[len(s)//2+1:]
if left == right[::-1]:
return True
return False
for i in range(int(input())):
n = int(input())
factors = findFactors(n)
cnt = 0
for f in factors:
if isPalindrome(str(f)):
cnt += 1
print(f"Case #{i+1}: " + str(cnt))
728x90
300x250
'코딩 테스트 > Google Kick Start' 카테고리의 다른 글
[Google Kick Start] 2021 구글 킥스타트 Round D Cutting Intervals 풀이 (0) | 2022.01.12 |
---|---|
[Google Kick Start] 2021 구글 킥스타트 Round B Consecutive Primes 풀이 (0) | 2022.01.08 |
[Google Kick Start] 2021 구글 킥스타트 Round A Rabbit house 풀이 (0) | 2021.12.19 |
[Google Kick Start] 2021 구글 킥스타트 Round A L shaped plots 풀이 (0) | 2021.12.18 |
[Google Kick Start] 2021 구글 킥스타트 Round G Staying Hydrated 풀이 (0) | 2021.12.08 |
Comments