문제
다음과 같이 Encoding 을 한다.
1. 우선 24비트 버퍼에 위쪽(MSB)부터 한 byte씩 3 byte의 문자를 집어넣는다.
2. 버퍼의 위쪽부터 6비트씩 잘라 그 값을 읽고, 각각의 값을 아래 [표-1] 의 문자로 Encoding 한다.
입력으로 Base64 Encoding 된 String 이 주어졌을 때, 해당 String 을 Decoding 하여, 원문을 출력하는 프로그램을 작성하시오.
제약사항
문자열의 길이는 항상 4의 배수로 주어진다.
그리고 문자열의 길이는 100000을 넘지 않는다.
입력
입력은 첫 줄에 총 테스트 케이스의 개수 T가 온다.
다음 줄부터 각 테스트 케이스가 주어진다.
테스트 케이스는 Encoding 된 상태로 주어지는 문자열이다.
10 TGlmZSBpdHNlbGYgaXMgYSBxdW90YXRpb24u U3VzcGljaW9uIGZvbGxvd3MgY2xvc2Ugb24gbWlzdHJ1c3Qu VG8gZG91YnQgaXMgc2FmZXIgdGhhbiB0byBiZSBzZWN1cmUu T25seSB0aGUganVzdCBtYW4gZW5qb3lzIHBlYWNlIG9mIG1pbmQu QSBmdWxsIGJlbGx5IGlzIHRoZSBtb3RoZXIgb2YgYWxsIGV2aWwu ... |
출력
테스트 케이스 t에 대한 결과는 “#t”을 찍고, 한 칸 띄고, 정답을 출력한다.
#1 Life itself is a quotation. #2 Suspicion follows close on mistrust. #3 To doubt is safer than to be secure. #4 Only the just man enjoys peace of mind. #5 A full belly is the mother of all evil. #6 A gift in season is a double favor to the needy. #7 Books are ships which pass through the vast seas of time. #8 Let thy speech be short, comprehending much in few words. #9 The world is a beautiful book, but of little use to him who cannot read it. #10 He who spares the rod hates his son, but he who loves him is careful to discipline him. |
코드
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
//encode -> decode
import java.util.*; class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i=0; i<t; i++){
String encodedString = sc.next();
byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
String decodedString = new String(decodedBytes);
System.out.printf("#%d %s\n", i+1, decodedString);
}
}
}
|
cs |
'SW expert Academy > D2' 카테고리의 다른 글
[SW Expert Academy] 1288번 새로운 불면증 치료법 (0) | 2023.05.17 |
---|---|
[SW Expert Academy] 1928번 Base64 Decoder 변형 문제 (0) | 2023.05.17 |
[SW Expert Academy] 1940번 가랏! RC카! (0) | 2023.05.12 |
[SW Expert Academy] 1946번 간단한 압축 풀기 (0) | 2023.05.12 |
[SW Expert Academy] 1948번 날짜 계산기 (0) | 2023.05.12 |