

2진수: 111 001 100
queue.size() == 9
9/3 = 3 => 0이 필요없음
2진수: 11 001 100
queue.size() == 8
8/3 = 2 ... 2 => 0이 1개필요
2진수: 1 001 100
queue.size() == 7
7/2 = 2 ... 1 => 0이 2개필요
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static StringBuilder sb = new StringBuilder();
public static Queue<Integer> queue = new LinkedList<>();
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] arrStr = br.readLine().split("");
int[] arrInt = new int[arrStr.length];
for (int i = 0; i < arrStr.length; i++) {
arrInt[i] = Integer.parseInt(arrStr[i]);
queue.add(arrInt[i]);
}
if (queue.size()%3 == 0) {
binaryToOctal(queue);
} else if (queue.size()%3 == 1){
sb.append(queue.poll());
binaryToOctal(queue);
} else {
sb.append(queue.poll()*2+queue.poll());
binaryToOctal(queue);
}
System.out.println(sb);
}
public static void binaryToOctal (Queue<Integer> queue) {
int size = queue.size();
// 2진수를 3씩 묶은 칸 수 만큼 반복 진행
for (int i = 0; i < size/3; i++) {
int[] tmp = new int[3];
int result = 0;
//한 칸 내에서 j의 수에 따라 연산 수행
for (int j = 0; j < 3; j++) {
tmp[j] = queue.poll();
if (j == 0)
result += tmp[j]*4;
else if (j == 1)
result += tmp[j]*2;
else
result += tmp[j];
}
sb.append(result);
}
}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String S = br.readLine();
//형변환을 해주면서 옆에 2를 적어주면 10진수로 바꿔준다.
BigInteger N = new BigInteger(S, 2);
//BigInteger.toString이 String으로 형변환 해주는 것이고, 옆에 괄호안에 원하는 진수를 적어주면 된다.
String result = N.toString(8);
System.out.println(result);
}
}