Skip to content

Commit 2620f7d

Browse files
committed
[D2] Title: Base64 Decoder, Time: 61 ms, Memory: 53,504 KB -BaekjoonHub
1 parent 3cfe6d6 commit 2620f7d

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
T = int(input())
2+
3+
# Base64 표준 문자 매핑
4+
base64_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
5+
6+
for tc in range(1, T+1):
7+
encoded = input()
8+
9+
# 패딩 문자 제거
10+
padding_count = encoded.count('=')
11+
encoded = encoded.rstrip('=')
12+
13+
# 이진수로 변환
14+
binary = ''
15+
for char in encoded:
16+
if char in base64_chars:
17+
binary += bin(base64_chars.index(char))[2:].zfill(6)
18+
19+
# 패딩 비트 제거
20+
if padding_count > 0:
21+
binary = binary[:-padding_count*2]
22+
23+
# 8비트씩 묶어서 ASCII 문자로 변환
24+
result = ''
25+
for i in range(0, len(binary), 8):
26+
if i + 8 <= len(binary):
27+
byte = binary[i:i+8]
28+
result += chr(int(byte, 2))
29+
30+
print(f"#{tc} {result}")
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# [D2] Base64 Decoder - 1928
2+
3+
[문제 링크](https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PR4DKAG0DFAUq)
4+
5+
### 성능 요약
6+
7+
메모리: 53,504 KB, 시간: 61 ms, 코드길이: 769 Bytes
8+
9+
### 제출 일자
10+
11+
2025-05-23 13:18
12+
13+
14+
15+
> 출처: SW Expert Academy, https://swexpertacademy.com/main/code/problem/problemList.do

0 commit comments

Comments
 (0)