import sys
input = sys.stdin.readline
a = input().strip()
lth = len(a)
ha, hb = a[:lth//2], a[lth//2:]
dt = {'A':0, 'B':1, 'C':2, 'D':3, 'E':4, 'F':5, 'G':6, 'H':7, 'I':8, 'J':9, 'K':10, 'L':11, 'M':12, 'N':13, 'O':14, 'P':15, 'Q':16, 'R':17, 'S':18, 'T':19, 'U':20, 'V':21, 'W':22, 'X':23, 'Y':24, 'Z':25}
ra=0
rb=0
ra = sum(dt[ch] for ch in ha)
rb = sum(dt[ch] for ch in hb)
def rotate(string, rotation_value):
rotated = ''
for ch in string:
rotated += chr((((ord(ch)-ord('A'))+rotation_value)%26)+ord('A'))
return rotated
ha_rotated = rotate(ha, ra)
hb_rotated = rotate(hb, rb)
result = ''
for i in range(len(ha_rotated)):
merged_ch = chr((((ord(ha_rotated[i])-ord('A'))+(ord(hb_rotated[i])-ord('A')))%26)+ord('A'))
result += merged_ch
print(result)
(1) 입력 처리 및 분할
input().strip()으로 개행 문자 제거.
문자열을 반으로 정확히 나눔.
(2) 회전 값 계산
각 문자열의 문자 값의 합계를 계산하여 회전 값을 구함.
(3) 문자열 회전
각 문자열을 회전 값만큼 회전:
알파벳 문자 범위를 벗어나지 않도록 모듈러 연산(% 26)을 사용.
(4) 문자열 병합
두 문자열을 병합하며 최종 결과 생성:
각 문자에서 두 번째 문자열의 해당 문자 값만큼 추가 회전.
(5) 출력
최종 복호화된 결과를 출력.
메모리: 32412 KB, 시간: 40 ms
구현, 문자열
2025년 1월 19일 12:10:50
DRM Encryption is a new kind of encryption. Given an encrypted string (which we’ll call a DRM message), the decryption process involves three steps: Divide, Rotate and Merge. This process is described in the following example with the DRM message “EWPGAJRB”:
The input contains a single DRM message to be decrypted. All characters in the string are uppercase letters and the string’s length is even and ≤ 15 000.
Display the decrypted DRM message.