https://www.acmicpc.net/problem/1212
1212번: 8진수 2진수
첫째 줄에 8진수가 주어진다. 주어지는 수의 길이는 333,334을 넘지 않는다.
www.acmicpc.net
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
string str;
cin >> str;
for (int i = 0; i <str.length() ; i++) {
int a[3] = { 0, };
for (int j = 0; j < 3; j++) {
a[j] = str[i] % 2;
str[i] /= 2;
}
for (int j = 2; j >= 0; j--) {
if (i == 0) {
if (j == 2 && a[j] == 0)
continue;
if (j == 1 && a[j + 1] == 0 && a[j] == 0)
continue;
}
cout << a[j];
}
}
return 0;
}
극한의 하드코딩으로 작성
'코딩테스트 > C++' 카테고리의 다른 글
| [백준 C++] 17103번: 골드바흐 파티션 (1) | 2024.04.20 |
|---|---|
| [백준 C++] 2089번: -2진수 (0) | 2024.04.20 |
| [백준 C++] 1373번: 2진수 8진수 (0) | 2024.04.19 |
| [백준 C++] 17087번: 숨바꼭질 6 (0) | 2024.04.18 |
| [백준 C++] 9613번: GCD 합 (0) | 2024.04.17 |