8월 22일

 

 

 

문제를 이해하는데 조금 오래걸렸다.
이거였음.

 

 

#include <string>
#include <vector>
#include<iostream>
using namespace std;

vector<int> solution(string s) {
    vector<int> answer = {0,0};
    while(1){
        int len = 0;
        
        for(auto x : s) x=='0'? answer[1]++ : len++;
        answer[0]++;
        if(len == 1) break;
        
        cout << answer[0] << "+++++" << answer[1] << "\n"; // 돌아가는 과정 확인용
        
        //이진법 변환하기
        s.clear();
        while(len!=1){
            s = to_string(len%2)+s;
            len/=2;
            cout << s << " // " << len << "\n"; // 돌아가는 과정 확인용
        }
        s = '1' + s;
    }
    return answer;
}

이진법 변환을 왜 저렇게 하냐면...

이거 푸는 저때는 비트변환을 공부하지 않았기 때무니지...

+ Recent posts