본문 바로가기
Coding Test/Programmers

[Programmers] (월간 코드 챌린지 시즌1) Lv 2. 이진 변환 반복하기

by song.ift 2023. 5. 16.

https://school.programmers.co.kr/learn/courses/30/lessons/70129?language=cpp 

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>

using namespace std;

vector<int> solution(string s) {
    int count{0}, erase{0};

    while (s != "1")
    {
        while (find(s.begin(), s.end(), '0') != s.end())
        {
            s.erase(find(s.begin(), s.end(), '0'));
            ++erase;
        }

        s = bitset<100>(s.length()).to_string();
        s = s.substr(s.find('1'));
        ++count;
    }

    return { count, erase };
}

GitHub : https://github.com/developeSHG/Algorithm-Baekjoon_Programmers/blob/aec88660114c9bb5eb6271bc8c2be5d6fd4d9aa3/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4/lv2/70129.%E2%80%85%EC%9D%B4%EC%A7%84%E2%80%85%EB%B3%80%ED%99%98%E2%80%85%EB%B0%98%EB%B3%B5%ED%95%98%EA%B8%B0/%EC%9D%B4%EC%A7%84%E2%80%85%EB%B3%80%ED%99%98%E2%80%85%EB%B0%98%EB%B3%B5%ED%95%98%EA%B8%B0.cpp

 

GitHub - developeSHG/Algorithm-Baekjoon_Programmers: 백준 and 프로그래머스 소스코드

백준 and 프로그래머스 소스코드. Contribute to developeSHG/Algorithm-Baekjoon_Programmers development by creating an account on GitHub.

github.com

 

댓글