https://www.acmicpc.net/problem/1373
1373번: 2진수 8진수
첫째 줄에 2진수가 주어진다. 주어지는 수의 길이는 1,000,000을 넘지 않는다.
www.acmicpc.net
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
string str;
cin >> str;
while (str.length() % 3 != 0) {
str = '0' + str;
}
for (int i = 0; i <str.length() ; i+=3) {
int a = 0;
a = 1 * (str[i + 2] - '0') + 2 * (str[i + 1] - '0') + 4 * (str[i] - '0');
cout << a;
}
return 0;
}
'코딩테스트 > C++' 카테고리의 다른 글
| [백준 C++] 2089번: -2진수 (0) | 2024.04.20 |
|---|---|
| [백준 C++] 1212번: 8진수 2진수 (1) | 2024.04.20 |
| [백준 C++] 17087번: 숨바꼭질 6 (0) | 2024.04.18 |
| [백준 C++] 9613번: GCD 합 (0) | 2024.04.17 |
| [백준 C++] 2004번: 조합 0의 개수 (0) | 2024.04.17 |