본문 바로가기
python-algorithm

백준 2999 비밀 이메일

by 무적김두칠 2022. 10. 3.

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

 

2999번: 비밀 이메일

정인이는 원래 "bombonisuuladici"를 보내려고 했다. 이 메시지는 16글자이므로, 정인이는 1*16, 2*8, 4*4 행렬을 선택할 수 있다. R이 가장 큰 것은 4*4이므로, 4*4를 선택한다. 정인이가 만든 행렬은 다음과

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
def cal(n):
    r,c=0,0
    for i in range(1, n):
        if n%i==0 and i<=n//i:
            r,c= i,n//i
    return r,c
def sol(s,r,c):
    answer=[]
    for i in range(c):
        tmp=''
        for j in range(r):
            tmp+=s[r*i+j]
        answer.append(tmp)
    answer_string=''
    for i in range(r):
        for j in range(c):
            answer_string+=answer[j][i]
    return answer_string
s=input()
r,c=cal(len(s))
print(sol(s,r,c))
cs

cal 함수는 r,c를 조건에 맞게 구하는 함수입니다.
(Cal fucntion is to calculate r, c in this problem)

sol 함수는
크게 두가지 내용인데
첫번째는 메세지를 행렬에 맞게 쪼개는 것, 그리고 두번째 문제 내용처럼 위에서 아래로 읽는것
(sol fucntion is Main function, First of all this means split the message into matrix, and read like the way which is like in problem Up and downs)

반응형

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

백준 2605 줄 세우기  (0) 2022.10.04
백준 10988 팰린드롬인지 확인하기  (0) 2022.10.04
백준 baekjoon 2846 오르막길  (0) 2022.09.29
백준 11005 진법 변환 2  (0) 2022.09.28
백준 25183 인생은 한 방  (0) 2022.09.27

댓글