1212번: 8진수 2진수
첫째 줄에 8진수가 주어진다. 주어지는 수의 길이는 333,334을 넘지 않는다.
www.acmicpc.net
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
string eight[8] = {"000","001","010","011","100","101","110","111"};
int main(){
string s;
cin >> s;
bool start = true;
if (s.length() == 1 && s[0]-'0' == 0) {
cout << "0";
}
for (int i=0; i<s.length(); i++) {
int n = s[i]-'0';
if (start == true && n < 4) {
if (n == 0) {
continue;
} else if(n == 1) {
cout << "1";
} else if (n == 2) {
cout << "10";
} else if (n == 3) {
cout << "11";
}
start = false;
} else {
cout << eight[n];
start = false;
}
}
return 0;
}
'Problem set' 카테고리의 다른 글
[백준] 1406: 에디터 (0) | 2020.12.29 |
---|---|
[백준] 1373: 2진수 8진수 (0) | 2020.12.29 |
[백준] 1158: 요세푸스 문제 (0) | 2020.12.29 |
[백준] 1110: 더하기 사이클 (0) | 2020.12.29 |
[백준] 1065: 한수 (0) | 2020.12.29 |