문제 : https://www.acmicpc.net/problem/1212


[알고리즘풀이]

8진수 1칸은 2진수 3칸으로 바꿀 수 있다.

#include<iostream>
#include<string>

using namespace std;

int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string input;
	cin >> input;
	for (int i = 0; i < input.length(); i++) {
		int t = input[i] - '0', tl[3];
		for (int j = 0; j < 3; j++) {
			tl[j] = t % 2;
			t /= 2;
		}
		if (i == 0) {
			if (tl[2] == 0 && tl[1] == 0)
				cout << tl[0];
			else if (tl[2] == 0)
				cout << tl[1] << tl[0];
			else
				cout << tl[2] << tl[1] << tl[0];
		}
		else {
			for (int j = 2; j >= 0; j--)
				cout << tl[j];
		}
	}
}

 

'Problem Solving > BOJ' 카테고리의 다른 글

[BOJ] 1644 - Sum of Consecutive Prime  (0) 2019.09.24
[BOJ] 2875 - TIMSKO  (0) 2019.09.23
[BOJ] 4355 - Relatives  (2) 2019.09.23
[BOJ] 14889 - 스타트와 링크  (0) 2019.09.21
[BOJ] 14888 - 연산자 끼워넣기  (0) 2019.09.21

+ Recent posts