본문 바로가기
python-algorithm

백준 6500 랜덤 숫자 만들기

by 무적김두칠 2022. 12. 6.

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

 

6500번: 랜덤 숫자 만들기

입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 한 줄이며, a0을 포함하고 있다. (0 < a0 < 10000) 숫자가 네 자리가 아닌 경우에는, 앞에 0을 추가해 네 자리로 만들어져 있다.

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def sol(s,n):
    answer = [s]
    while True:
        s = str(int(s)**2).zfill(n*2)
        s = s[n//2:2*n-n//2]
        if s not in answer:
            answer.append(s)
        else:
            return len(answer)
 
if __name__ == '__main__':
    while True:
        s = input()
        n = 4
        if s == '0':
            break
        print(sol(s,n))
 
cs

Line 4 : 제곱하고 0 채워넣는 부분
Line 5 : 숫자 중간부분

Line 4 : It means squares number and fill the zero in number
Line 5 : Find middle part of number 

반응형

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

백준 9713 Sum of Odd Sequence  (0) 2022.12.06
백준 26041 비슷한 전화번호 표시  (0) 2022.12.06
백준 7120 String  (0) 2022.12.05
백준 6438 Reverse Text  (1) 2022.12.05
백준 13234 George Boole  (0) 2022.12.05

댓글