CT/SWEA

[SWEA][D3][Python] 14361. 숫자가 같은 배수

hyunji1109 2023. 7. 1. 16:10

https://swexpertacademy.com/main/solvingProblem/solvingProblem.do

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 


 

  1.  k를 1씩 증가시키면서 n과 곱한다.
  2. 곱한 값을 list형태로 변경하여 내림차순으로 정렬했을 때 n2 내림차순과 같은 경우 possible을 출력한다.
  3.  재배열이기 때문에 result 길이가 n의 길이보다 커지면 impossibel을 출력한다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
= int(input())
 
for test_case in range(1, T + 1):
    n = input()
    n2 = list(str(n))
    k = 2
    answer = 'impossible'
    
    while True:
        result = int(n) * k
        if sorted(list(str(result))) == sorted(n2):
            answer = 'possible'
            break
            
        if len(list(str(result))) > len(n2):
            break
        
        k += 1
    
    print(f'#{test_case} {answer}')
            
cs