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;
}
이진법 변환을 왜 저렇게 하냐면...
이거 푸는 저때는 비트변환을 공부하지 않았기 때무니지...
'C++ 문제풀기 > 백준-프로그래머스' 카테고리의 다른 글
| 프로그래머스 | 짝지어 제거하기 (0) | 2025.09.13 |
|---|---|
| 프로그래머스 | N 보다 큰 수 (0) | 2025.09.13 |
| 프로그래머스 | 최댓값과 최솟값 (0) | 2025.09.13 |
| 프로그래머스 | [PCCP 기출문제] 1번 / 동영상 재생기 (0) | 2025.09.13 |
| 백준 | 2839. 설탕배달 (7) | 2025.07.02 |