Baekjoon #1212

Baekjoon #1212

2개의 풀이 · C++, Python

문제 원문 보기 ↗

SOLUTION INFO

C++ · main.cpp

main.cpp
#include<bits/stdc++.h>

using namespace std;

string convert(char s, bool fillzero=false){
    int n = s - 48;
    string ret = "";
    while(n){
        ret += (n % 2) + '0';
        n /= 2;
    }
    while(fillzero && (int)ret.size() < 3) ret += '0';
    reverse(ret.begin(), ret.end());
    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;cin >> s;
    if(s == "0") {
        cout << 0;
        return 0;
    }
    string ans="";
    for(int i=0;i<(int)s.size();i++){
        ans += convert(s[i], i != 0);
    }
    cout << ans;

    return 0;
}

SOLUTION DESCRIPTION

풀이 설명

등록된 풀이 설명이 없습니다.