본문 바로가기

Programming/BaekJoon

[C++] 백준 1094번 : 막대기


https://www.acmicpc.net/problem/1094




#include <iostream>

using namespace std;


int main() {

int x;

cin >> x;

int cnt = 1;

while (x != 1) {

if (x % 2 == 1)

cnt++;

x = x / 2;

}

cout << cnt;

}